I can not figure out how to use the wait( ) feature. For example I am making a brick that makes you fall if you don't walk across fast enough. I wrote the script using this format
local trapdoor = workspace.trapdoor
function onTouch(part)
trapdoor.CanCollide = true trapdoor.CanCollide = true trapdoor.Transparency = 0 wait(.5) trapdoor.CanCollide = false trapdoor.Transparency = .3 wait(2) trapdoor.CanCollide = true trapdoor.Transparency = 0
end
trapdoor.Touched:connect(onTouch)
when i walk on the block it works but if i jump when it starts to go away the script resets rather than continuing the rest of the script. PLEASE HELP ME TIME SCRIPT TO ONLY WORK EVERY SO MANY SECONDS!!! HELP!!!~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~
debounce = false function OnTouch(hit) if debounce == false then debounce = true wait(1) --TIME FOR PLAYER TO MOVE script.Parent.CanCollide = false script.Parent.Transparency = 0.25 wait(0.25) script.Parent.Transparency = 0.5 wait(0.25) script.Parent.Transparency = 0.75 wait(0.25) script.Parent.Transparency = 1 wait(5) --Time until reset script.Parent.Transparency = 0 script.Parent.CanCollide = true wait() debounce = false end end
This is how I would have done it. If you have questions, type them in the comments. Thumbs up if this helped the most :)
You need to use a debounce, it prevents from too many events from happening
debounce = false function OnTouch(hit) if debounce then return else debounce = true end --ACTION debounce = false end