Make A Touched Event Fire Once

Hello, I am having issues with my code where a player touches it too much, any way to make it be touched only once? Thanks!

3 Likes

Mk this is quite easy, either you could make an inf debounce or, you could make a loop that checks if the event “has” been fired:
debounce example

local debounce = false
-- touch function()
if db = false then
db = true
-- fire function()

hope this helps.

1 Like

Have this!

2 Likes

Make a debounce, a debounce stops from it being touched that much and you can add a wait period as well

local debounce = true
local cooldown = 1

script.Parent:Touched(function(hit)
       if hit.Parent:FindFirstChild("Humanoid") ~= nil and debounce == true then
       debounce = false
       -- Code Here
       -- wait(cooldown) -- Optional Cooldown
       debounce = true
end)
6 Likes

This is a little less popular, but depending on your use, you could also do something like this

local func
func = Thing.Touched:Connect(function(TouchedBy)
func:Disconnect()
end)

Debounces are a better idea, just throwing in my own incase someone finds it useful for anything

5 Likes