I have this little project of mine and i needed to add a debounce to a function. I've tried for hours but i can't figure it out. Piece of code below.
local part = --reminder to do this part.Touched:connect(function(hit) if hit.Parent and hit.Parent:FindFirstChild("Humanoid") then hit.Parent.Humanoid:TakeDamage(1) end end)
Debounce requires use of a boolean and a wait() statement to determine when the player is allowed to fire an event.
In your case, your script would look something like this:
local part = ... local debounce = false part.Touched:Connect(function(hit) -- :connect() is deprecated, use :Connect() instead if hit.Parent:FindFirstChild("Humanoid") and not debounce then -- Only fire the event if the debounce is set to false debounce = true -- Set the debounce to true so that the player can't fire the event again hit.Parent.Humanoid:TakeDamage(1) wait(1) -- However long you want to wait before the player can get damaged again debounce = false end end)
Hope this answered your question.