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

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

Asked by 9 years ago

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 — 9y

2 answers

Log in to vote
3
Answered by 9 years ago
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 — 9y
Ad
Log in to vote
2
Answered by 9 years ago

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 — 9y
0
Thanks for noticing that XD TopKekBD 15 — 9y
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 — 9y
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 — 9y
View all comments (3 more)
0
I dont understand the function this will add to my script can you please type an small example script show how the debounce would look in a average script please. Or type it into the script i added to the question? brooksdart 5 — 9y
0
Don't worry, I've provided a small example at your other question regarding debouncing. Redbullusa 1580 — 9y
0
Basicly, imagine this, the debounce is a off/on switch. The "if then" asks if the debounce is on, if it is on, then it will return, AKA stop the function. Else if it is off, then the debounce will be on, and it will be turned off at the end. TopKekBD 15 — 9y

Answer this question