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)
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)
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.
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)
function onTouched(hit) while true do script.Parent.Chaching:play() wait(120) end end script.Parent.Touched:connect(onTouched)