generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Make a new part on touch, Materials & Colours not working

Previous Thread :: Next Thread 
fartyburp is not online. fartyburp
Joined: 21 May 2011
Total Posts: 3222
30 Mar 2015 01:51 PM
script.Parent.Touched:connect(function()
local p = Instance.new('Part')
script.Parent.Anchored = true
script.Parent.BrickColor = BrickColor.new("Really red")
script.Parent.Material = ("Granite")
p.Parent,p.Position = workspace,Vector3.new(88.8,2,41)
end)


but that didn't work.
Also its making about 8 of them when I click, because its not on a timer or something, I only want it to make one. :/
I'm very new to scripting & trying to learn.


Help?
Report Abuse
Bebee2 is not online. Bebee2
Joined: 17 May 2009
Total Posts: 3985
30 Mar 2015 01:55 PM
-- You'll need this concept you'll see sometimes
-- http://wiki.roblox.com/index.php?title=Debounce
local debounceVariable = false

script.Parent.Touched:connect(function()
if debounceVariable == false then
debounceVariable = true
local p = Instance.new('Part')
script.Parent.Anchored = true
script.Parent.BrickColor = BrickColor.new("Really red")
script.Parent.Material = ("Granite")
p.Parent,p.Position = workspace,Vector3.new(88.8,2,41)
end
end)
Report Abuse
instawin is not online. instawin
Joined: 04 Jun 2013
Total Posts: 8777
30 Mar 2015 01:58 PM
function onTouched(hit) -- create a new function, give a parameter of hit. .Touched takes a parameter of hit, hit being the part that touched your script.Parent for instance. you can name the parameter whatever you want

local part = Instance.new("Part") -- the new part
part.Parent = game.Workspace -- give it a parent
part.Anchored = true -- anchor the new part that we just created
part.BrickColor = BrickColor.new("Really red") -- give the new part a new brick color
part.Material = "Granite"-- give the new part we create a new material
part.Position = Vector3.new(88.8, 2, 41) -- give the new part a position
end
Report Abuse
fartyburp is not online. fartyburp
Joined: 21 May 2011
Total Posts: 3222
30 Mar 2015 01:58 PM
Didnt work :(
Report Abuse
instawin is not online. instawin
Joined: 04 Jun 2013
Total Posts: 8777
30 Mar 2015 02:00 PM
whoops i accidentally posted it when it wasnt finished, i forgot to connect the function and use the hit parameter

function onTouched(hit) -- create a new function, give a parameter of hit. .Touched takes a parameter of hit, hit being the part that touched your script.Parent for instance. you can name the parameter whatever you want

if hit and hit.Parent then -- make sure hit has a parent
local part = Instance.new("Part") -- the new part
part.Parent = game.Workspace -- give it a parent
part.Anchored = true -- anchor the new part that we just created
part.BrickColor = BrickColor.new("Really red") -- give the new part a new brick color
part.Material = "Granite"-- give the new part we create a new material
part.Position = Vector3.new(88.8, 2, 41) -- give the new part a position
end
end

script.Parent.Touched:connect(onTouched)
Report Abuse
Bebee2 is not online. Bebee2
Joined: 17 May 2009
Total Posts: 3985
30 Mar 2015 02:01 PM
-- Internet D/C'd... this post is prolly really late.
-- I reckon you want to change p's properties, not script.Parent

script.Parent.Touched:connect(function()
if debounceVariable == false then
debounceVariable = true
local p = Instance.new('Part')
p.Anchored = true
p.BrickColor = BrickColor.new("Really red")
p.Material = ("Granite")
p.Parent,p.Position = workspace,Vector3.new(88.8,2,41)
end
end)
Report Abuse
instawin is not online. instawin
Joined: 04 Jun 2013
Total Posts: 8777
30 Mar 2015 02:04 PM
use be's script, it's better

i thought to explain .Touched's parameter more because it seemed you didn't understand it at first
Report Abuse
fartyburp is not online. fartyburp
Joined: 21 May 2011
Total Posts: 3222
30 Mar 2015 02:07 PM
Neither of them worked, sorry guys XD
Report Abuse
Bebee2 is not online. Bebee2
Joined: 17 May 2009
Total Posts: 3985
30 Mar 2015 02:08 PM
-- Works fine for me
-- Script used:

script.Parent.Touched:connect(function()
if debounceVariable == false then
debounceVariable = true
local p = Instance.new('Part')
p.Anchored = true
p.BrickColor = BrickColor.new("Really red")
p.Material = ("Granite")
p.Parent,p.Position = workspace,Vector3.new(88.8,2,41)
debounceVariable = false
end
end)
Report Abuse
instawin is not online. instawin
Joined: 04 Jun 2013
Total Posts: 8777
30 Mar 2015 02:11 PM
touched = false

script.Parent.Touched:connect(function(hit)
if not touched and hit and hit.Parent then
touched = true
local part = Instance.new("Part")
part.Parent = game.Workspace
part.BrickColor = BrickColor.new("Bright red")
part.Anchored = true
part.Material = "Granite"
part.Position = Vector3.new(5,5,5)
wait(3)
touched = false
end
end)

that should work
i don't see why my original one would error, the only problem with mine was it didnt have a debounce

i used an anonymous function now because they are quicker
Report Abuse
Bebee2 is not online. Bebee2
Joined: 17 May 2009
Total Posts: 3985
30 Mar 2015 02:13 PM
-- And I clipped off a line.

local debounceVariable = false

script.Parent.Touched:connect(function()
if debounceVariable == false then
debounceVariable = true
local p = Instance.new('Part')
p.Anchored = true
p.BrickColor = BrickColor.new("Really red")
p.Material = ("Granite")
p.Parent,p.Position = workspace,Vector3.new(88.8,2,41)
debounceVariable = false
end
end)
Report Abuse
fartyburp is not online. fartyburp
Joined: 21 May 2011
Total Posts: 3222
30 Mar 2015 02:16 PM
Thanks so much guys, it worked! ^.^
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image