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 10 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)

1trapdoor.CanCollide = true
2trapdoor.CanCollide = true
3trapdoor.Transparency = 0
4wait(.5)
5trapdoor.CanCollide = false
6trapdoor.Transparency = .3
7wait(2)
8trapdoor.CanCollide = true
9trapdoor.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 — 10y

2 answers

Log in to vote
3
Answered by 10 years ago
01debounce = false
02function OnTouch(hit)  
03        if debounce == false then
04        debounce = true
05        wait(1) --TIME FOR PLAYER TO MOVE
06        script.Parent.CanCollide = false
07        script.Parent.Transparency = 0.25
08        wait(0.25)
09        script.Parent.Transparency = 0.5
10        wait(0.25)
11        script.Parent.Transparency = 0.75
12        wait(0.25)
13        script.Parent.Transparency = 1
14        wait(5) --Time until reset
15        script.Parent.Transparency = 0
16        script.Parent.CanCollide = true
17        wait()
18        debounce = false
19    end        
20end

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

You need to use a debounce, it prevents from too many events from happening

1debounce = false
2function OnTouch(hit)
3    if debounce then return else debounce = true end
4    --ACTION
5    debounce = false
6end
1
You have uppercased the 'I' in 'if'; consider changing to 'if'? :P TheeDeathCaster 2368 — 10y
0
Thanks for noticing that XD TopKekBD 15 — 10y
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 — 10y
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 — 10y
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 — 10y
0
Don't worry, I've provided a small example at your other question regarding debouncing. Redbullusa 1580 — 10y
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 — 10y

Answer this question