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

How would i add a wait() to this???

Asked by
22To 70
10 years ago

i need this to wait 120 seconds before making the noise again

1function onTouched(hit)
2    script.Parent.Chaching:play()
3end
4script.Parent.Touched:connect(onTouched)

4 answers

Log in to vote
2
Answered by 10 years ago

Please provide explanation with your answers. Simply posting code does not spread knowledge of integral scripting processes which helps people understand the logic and reasoning behind your answer.
01local touched = false
02local waittime = 120 -- seconds to wait
03 
04script.Parent.Touched:connect(function(hit)
05    if not touched then --if the debounce variable is false, then
06        touched = true --make it true!
07        script.Parent.Chaching:play() --plays the sound in the brick
08        wait(waittime)  --waits what you put as the variables "waittime" until it can be fired again
09    end
10    touched = false --make it false again so we can do the if statement again after your waittime
11end)
2
Don't just provide code, explain it. Just providing code without an explanation doesn't let them learn anything. Goulstem 8144 — 10y
Ad
Log in to vote
1
Answered by 10 years ago

You would have to create a debounce.

You can see one here: http://wiki.roblox.com/index.php?title=Debounce

1
For future reference - you should provide a code example with your explanation. Goulstem 8144 — 10y
Log in to vote
0
Answered by 10 years ago

Basically you would make a debounce.

Debounce in a way disables the script until it needs be used again.

01local debounce=false --Making a boolean value to use with debouncing the script
02function onTouched(hit)
03if debounce==false then -- Checks to see if the debounce is false
04debounce=true -- Setting it to true, so if something touches it before the time is up it does nothing
05    script.Parent.Chaching:play()
06wait(120)
07debounce=false -- Setting debounce back to false after 120 seconds so it can be activated again.
08end
09end
10script.Parent.Touched:connect(onTouched)
Log in to vote
0
Answered by 10 years ago
1function onTouched(hit)
2    while true do
3    script.Parent.Chaching:play()
4wait(120)
5end
6end
7script.Parent.Touched:connect(onTouched)
0
That's the simple way. All of the rest of you are complicated. Too complicated... Ethan_Waike 156 — 10y

Answer this question