So I'm trying to get this one brick to turn red once its been touched 4 times but I can't seem to get it to work.
This script is inside the actual brick itself.
i = 0 function touch(hit) i = i+1 end script.Parent.Touched:connect(touch) while i < 5 do wait(.5) if i == 4 then script.Parent.BrickColor = BrickColor.new("Bright red") print("Red") else print("Not Red") end end
I would recommend trying to use a check()
function rather than using a loop.
So you would add a function called check()
which would do this:
function check() if i == 4 then script.Parent.BrickColor = BrickColor.new("Bright red") print("Red") else print("Not Red") end end
And then remove your loop.
So your final script would go like this:
i = 0 function touch(hit) i = i+1 check() end function check() if i == 4 then script.Parent.BrickColor = BrickColor.new("Bright red") print("Red") else print("Not Red") end end script.Parent.Touched:connect(touch)
Hopefully that works for you!