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?

4 comments
I appreciate making it more efficient but it still does the 'flashing' thing. It's weird, when I walk on top of the brick, not jumping or anything, it flashes colors instead of staying one color. It's like I'm barely coming off the ground when I walk. Any other ideas?
Its because the event Touched fires continuously, only once, then TouchEnded fires, and back and forth they go, theres no way to really fix this, except put an extensive wait between the two.
Why not connect TouchEnded after the wait(1) on the Touched function in Xetrax's script? Or, why not use debounce?
@Spongocardo, how would I do that?