Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 7 years ago
Edited 7 years ago

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

Log in to vote
2
Answered by 7 years ago

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!

0
That worked! Thank you so much. MastahProdigy 10 — 7y
Ad

Answer this question