So I'm very new to scripting and I'm kinda bad. I'm trying to make a game where you can click on some cubes and they change color when you click on them, like a drawing game. There is also a button that resets the drawing and makes it all grey again. I've already figured out how to work the clear button but I wanted to make it fancier. I made it so when you click the clear button, it makes the cubes turn grey one by one with a 0.5 cooldown in between each one until they are all done. I noticed when I made that, it was going really slow because it was making the already grey cubes grey. I tried to fix this once again with the line of code I provided, but when I tested the clear button, nothing happened; not even an error. Please help me fix my button, it would be appreciated and help me learn from my mistakes :).
(don't judge my code lol) while workspace.Reset.ClickDetector.MouseClick:Wait() do local Parts = game.Workspace.Model:GetChildren() -- model is the canvas with all of the cubes for i, v in pairs(Parts) do if v.BrickColor == BrickColor.Gray() then return else v.BrickColor = BrickColor.Gray() wait() end end end
while workspace.Reset.ClickDetector.MouseClick:Wait() do local Parts = game.Workspace.Model:GetChildren() for i, v in pairs(Parts) do if v.BrickColor == BrickColor.Gray() then -- return halts the script else v.BrickColor = BrickColor.Gray() wait() end end end
Hopefully this works for you. Please mark this answer as correct if this was helpful!