1

# How to time the flow of the script using wait( )???

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!!!~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~

0
do i add this to the end or the start of the script and do i need to change anything before i do? besides the if brooksdart 5 — 8y

3
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 :)

0
so if im wrong all I need to do is place this script into the block i wish to add the function to and label the local names? ex: local p = workspace.p brooksdart 5 — 8y
2

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

1
You have uppercased the 'I' in 'if'; consider changing to 'if'? :P TheeDeathCaster 2368 — 8y
0
Thanks for noticing that XD TopKekBD 15 — 8y
0
is this already format for a touch script rather than a onClick script? can i just copy & paste to the end of my script? And thanks a lot for the info. I have been searching a while to see why the script is running from the start each time I touch it. I have read the debounce blog but couldn figure out how to convert it into a onTouch script rather than an onClick brooksdart 5 — 8y
0
What are you talking about, the debounce is compatible for every function, as long as you put a different variable for every different function. TopKekBD 15 — 8y