Howdy!
In the scripting world, we call this "debounce". Don't ask me why, the Code Gods just made it like that. The definition used by this site is:
Debounce is a term that is often associated with the act of adding a cool-down time to a function so it doesn't get called rapidly. This can be especially helpful when used in conjunction with the Touched event of parts. Oftentimes, this is accomplished by setting a variable to true at the beginning of a function, and setting it to false again at the end. Then, at the very beginning of the function, if the variable is already true, then you use the 'return' keyword, effectively ending the function.
Before your function, add a variable called "debounce" and set it to false. Then when the function is ran, set the debounce as true with a wait time of three seconds (or whatever you want). Take a look at the example I have below where I have a script set to print something upon the click from player on a ClickDetector.
local Debounce = false
local WaitTime = 3
script.Parent.MouseClick:Connect(function(Player)
if not Debounce then
Debounce = true
print("I just got clicked by ".. Player.Name .."!"
wait(WaitTime)
Debounce = false
end
end)
If this helped you out, consider accepting this answer for those sweet, sweet reputation points. If not, comment below and I (or someone else) will help you out.
Be sure to check out the Roblox API Documentation as well for additional reference.
2 comments
local Debounce = false local WaitTime = 2 function dmg(hit) if hit.Parent ~= nil then if not Debounce then Debounce = true local hum = hit.Parent:findFirstChild("Humanoid") if hum ~= nil then if hit.Parent ~= nil then hum.Health = hum.Health -10 wait(2) Debounce = false end end end end end rarm.Touched:connect(dmg) larm.Touched:connect(dmg) It didn't work :/
Did you get an error?