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

I would like to get a brick to turn red once it's been touched.. can anyone help?

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

1 answer

✓ Accepted answer

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!

1 comment

0

That worked! Thank you so much.

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