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
9 years ago

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

function onTouched(hit)
    script.Parent.Chaching:play()
end
script.Parent.Touched:connect(onTouched)

4 answers

Log in to vote
2
Answered by 9 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.
local touched = false
local waittime = 120 -- seconds to wait

script.Parent.Touched:connect(function(hit)
    if not touched then --if the debounce variable is false, then
        touched = true --make it true!
        script.Parent.Chaching:play() --plays the sound in the brick
        wait(waittime)  --waits what you put as the variables "waittime" until it can be fired again
    end
    touched = false --make it false again so we can do the if statement again after your waittime
end)
2
Don't just provide code, explain it. Just providing code without an explanation doesn't let them learn anything. Goulstem 8144 — 9y
Ad
Log in to vote
1
Answered by 9 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 — 9y
Log in to vote
0
Answered by 9 years ago

Basically you would make a debounce.

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

local debounce=false --Making a boolean value to use with debouncing the script
function onTouched(hit)
if debounce==false then -- Checks to see if the debounce is false
debounce=true -- Setting it to true, so if something touches it before the time is up it does nothing
    script.Parent.Chaching:play()
wait(120)
debounce=false -- Setting debounce back to false after 120 seconds so it can be activated again.
end
end
script.Parent.Touched:connect(onTouched)

Log in to vote
0
Answered by 9 years ago
function onTouched(hit)
    while true do
    script.Parent.Chaching:play()
wait(120)
end
end
script.Parent.Touched:connect(onTouched)
0
That's the simple way. All of the rest of you are complicated. Too complicated... Ethan_Waike 156 — 9y

Answer this question