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

Debounce | having trouble :( ?

game.Players.PlayerAdded:connect(function(player)
	script.Parent.Touched:connect(function()
		local plrstats = player.leaderstats.Timer
		local debounce = true
		if debounce ~= true then
			debounce = false
			plrstats.Value = plrstats.Value +100
			wait(2)
			debounce = true
		end
	end)
end)

1 answer

✓ Accepted answer

A simple fix; the only problem with your code is that you defined debounce too late in the script. You need to define it before the Touched listening event, and you need to make the conditional activate when the debounce is true like so:

game.Players.PlayerAdded:connect(function(player)
	local debounce = true
	script.Parent.Touched:connect(function()
		local plrstats = player.leaderstats.Timer
		if debounce then
			debounce = false
			plrstats.Value = plrstats.Value +100
			wait(2)
			debounce = true
		end
	end)
end)

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