Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Looking for help with ClickDetector controlling multiple parts at once.?

Asked by 4 years ago

I am currently working on a stage that has lights all over it. There are 9 ClickDetectors that'll change the colors of these parts. Right now, the script works, but only for 1 part. I am looking for a way to use one script to change all 36 part colors at the same time.

My current script:

local variable = script.Parent:WaitForChild("ClickDetector") MDST = game.Workspace.MDST.SL1

variable.MouseClick:Connect(function() MDST.BrickColor = BrickColor.new("Really red") end)

The part "SL1" goes up to "SL36". Should I name all of them different or keep them named the same? I've tried adding more parts to it (i.e "game.Workspace.MDST.SL1.SL2.SL3.etc) but it doesn't work. Then, I tried c/p "MDST = game.Workspace.MDST.etc" to add another part in, but it still only changes one part. Please drop down suggestions of ways to fix this, thanks!

0
loop through the all the children of workspace.MDST with a for loop theking48989987 2147 — 4y
0
how would I do that? CamiaCabora 5 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

After removing eveything that you do not want the change the color from the model use this:

script.Parent.ClickDetector.MouseClick:Connect(function()

    local bricks = game.Workspace.MDST:GetChildren() --Creates a table with every single part inside of the model
for i=1, #bricks do --creates a loop that will touch every single part inside of the table
    bricks[i].BrickColor = BrickColor.new("Really red") --changes the parts color to really red

end


end)
Ad

Answer this question