i need this to wait 120 seconds before making the noise again
1 | function onTouched(hit) |
2 | script.Parent.Chaching:play() |
3 | end |
4 | script.Parent.Touched:connect(onTouched) |
01 | local touched = false |
02 | local waittime = 120 -- seconds to wait |
03 |
04 | script.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 |
11 | end ) |
You would have to create a debounce.
You can see one here: http://wiki.roblox.com/index.php?title=Debounce
Basically you would make a debounce.
Debounce in a way disables the script until it needs be used again.
01 | local debounce = false --Making a boolean value to use with debouncing the script |
02 | function onTouched(hit) |
03 | if debounce = = false then -- Checks to see if the debounce is false |
04 | debounce = true -- Setting it to true, so if something touches it before the time is up it does nothing |
05 | script.Parent.Chaching:play() |
06 | wait( 120 ) |
07 | debounce = false -- Setting debounce back to false after 120 seconds so it can be activated again. |
08 | end |
09 | end |
10 | script.Parent.Touched:connect(onTouched) |
1 | function onTouched(hit) |
2 | while true do |
3 | script.Parent.Chaching:play() |
4 | wait( 120 ) |
5 | end |
6 | end |
7 | script.Parent.Touched:connect(onTouched) |