Well what I want to do as the Title says is have a code where every five clicks a brick will change colors. This is my code:
r = 0 script.Parent.ClickDetector.MouseClick:Connect(function() r = r + 1 print (r) end) while wait() do if r % 5 == 0 and r > 1 then script.Parent.BrickColor = BrickColor.Random() end end
Of course, the while loop runs as that is what it is supposed to do, and the brick surfs through colors every five clicks, instead of changing colors once. I tried using a debounce, and trying to have it not run until r = r + 5, however it takes the value of r outside of the function which would be 0 instead of the value of r currently. Any fixes? Thanks
local clicks = 0 script.Parent.ClickDetector.MouseClick:Connect(function(plr) clicks = clicks + 1 if clicks == 5 then script.Parent.BrickColor = BrickColor.Random() clicks = 0 -- Reset the clicks amount so we can do this again end end)