Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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!

2 comments

0

loop through the all the children of workspace.MDST with a for loop

0

how would I do that?

1 answer

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.