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

How do you correctly make this in my drawing game? (Im new).

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

1 comment

0

The return statement essentially stops the entire script from running. Leaving it empty or checking if v.BrickColor ~= BrickColor.Gray() instead would work

1 answer

✓ Accepted answer
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!

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