i made a part that when u touch it...it change color to red the script works pefectly......i want to copy the part and paste it so many times....but when i do it the copied once are not working...only the origial part is working....this is my script
brick = game.Workspace.Part function onTouch() brick.BrickColor = BrickColor.new("Really red") --You have to spell it end brick.Touched:connect(onTouch)
please tell me if there is something i should do to make the others part works when we touch them :( Thank you so much :D
The script only ever works for the one part because it finds the first part in workspace to use. To fix this, instead of going
brick = game.Workspace.Part
you can go
brick = script.Parent
which will mean the part that the script is inside of.
It may also be more efficient to have one script in the game, and put all the parts inside a model or folder called TouchParts, and do something like this:
for _,v in pairs(workspace.TouchParts:GetChildren()) do v.Touched:Connect(function() v.BrickColor = BrickColor.new("Really red") end) end
Doesn't work because you are only referencing one part being game.Workspace.Part, if you actually wanted to clone them then you'd do
script.Parent.Touched:Connect(function() script.Parent.BrickColor = BrickColor.new("Really Red") end)
But it seems sorta silly to have a ton of scripts doing the same thing, if you put all the parts into one parent (could be a folder, a model) you could do
for _, part in pairs(workspace.Parts:GetChildren()) -- In this example all parts must be in a child of workspace named "Parts" part.Touched:Connect(function() part.BrickColor = BrickColor.new("Really Red") end) end