Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How would I apply debounce to my script?

script.Parent.Touched:Connect(function(touched)
	script.Parent.Transparency = 0
	wait(3)
	script.Parent.Transparency = 1
	
end)

function spike(partTouching)
	if partTouching.Parent:FindFirstChild("Humanoid") then
		partTouching.Parent.Humanoid.Health = 0
	end
end

script.Parent.Touched:Connect(spike)

1 answer

Use this :

local Debounce = false

script.Parent.Touched:Connect(function(touched)
	if Debounce == false then
		Debounce = true
		--script here
		wait(1) -- amount of time to set Debounce = false
		Debounce = false
end
end)

if it doesn't work, tell me

2 comments

0

if (Debounce) then return end; Debounce = true. You can do all that in one line if you wish to, also, you forgot a to close your conditional scope.

0

oof forgot that

This discussion is preserved as it was. New answers, comments, and votes are closed.