Debouncing help, how to make it so a line of code can be triggered once and never again

hey guys, so I’ve recently ran into an issue I’m fairly new to scripting. and I’m just wondering how I can make it so once my code has been triggered, it cant be triggered again, for the odd reason of a player touching the same part for a second time? any help would be appreciated! You can take a look at my code below

local part = script.Parent
local isTouched = false

local function touched(player)
	if not isTouched then
		isTouched = true
	end
	print("success")
	isTouched = false
end

part.Touched:Connect(touched)
1 Like

Modify the code as such:

local function touched(player)
	if isTouched then
        return 
	end
	print("success")
	isTouched = true
end

Alternatively you can also use :Once rather than :Connect

woa
i didnt know :Once() existed
this is gonna be useful

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.