Please forgive me if this seems like something simple, I am currently a beginner in learning Lua. Anyways, I was trying to make a script in which when you are touching the brick (In my case when I am standing on top) the brick turns a different color (Blue), and when you step off of the brick it turns back to red. It does what it's supposed to do, however, when ever I walk across the brick it flashes between red and blue, kind of like I am not touching it when walking. I don't get it. If you don't know what I mean here is the script:
function onTouch() script.Parent.BrickColor = BrickColor.new("Bright blue") wait(1) end
function offTouch() script.Parent.BrickColor = BrickColor.new("Bright red") wait(1) end
script.Parent.Touched:connect(onTouch) script.Parent.TouchEnded:connect(offTouch)
Could someone help, and if possible maybe there is a more efficient way of doing this?
The only more efficient way I can think of goes like this:
script.Parent.Touched:connect(function() script.Parent.BrickColor = BrickColor.new("Bright blue") wait(1) end) script.Parent.TouchEnded:connect(function() script.Parent.BrickColor = BrickColor.new("Bright red") wait(1) end)
Shorter and should work a teensy bit faster, its just embedding a function within an event. Hope that helps!