I am having trouble with my script. I want to make everything inside a model named, "Boxes", turn to a random color each .5 seconds. But my current script only changes one part inside the model.
script.Parent.ClickDetector.MouseClick:Connect(function() script.Parent.BrickColor = BrickColor.Green() --changes button color for i, v in pairs(workspace.Boxes:GetChildren()) do if i == 3 then --checks to see if i has looped 3 times (which equals the # of boxes inside the model, "Boxes") while true do --should do a random color loop wait(.5) v.BrickColor = BrickColor.Random() wait(10) break end end end for i, v in pairs(workspace.Boxes:GetChildren()) do --changes boxes back to original color v.BrickColor = BrickColor.new("Medium stone grey") end script.Parent.BrickColor = BrickColor.Red() --changes button color end)
I'm not sure if i did the wait(10) break thing right but that's not what I'm asking y'all to fix. I'll fix that part on my own.
Heres some code i wrote works fine for me!
script.Parent.BrickColor = BrickColor.Green() local debounce = false script.Parent.ClickDetector.MouseClick:Connect(function() if debounce == false then -- this debounce is to stop ppl from spamming debounce = true script.Parent.BrickColor = BrickColor.Red() wait(.5) for i,v in pairs(game.workspace.boxes:GetChildren()) do wait(.5) if v:IsA("Part") then -- just sanitizing 4 no errors v.BrickColor = BrickColor.Random() end end wait(.5) for i,v in pairs(game.workspace.boxes:GetChildren()) do wait(.5) if v:IsA("Part") then -- just sanitizing 4 no errors v.BrickColor = BrickColor.new("Medium stone grey") end end wait(.5) script.Parent.BrickColor = BrickColor.Green() debounce = false end end)