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

Why does my debounce not work? {SOLVED}

This apparently gives the correct amount faster that it should. The pad is not meant to work every 5 seconds but apparently works every second? Help?

Admins = {36491121,32441993,37983438}
id = 232590627
debounce = true
script.Parent.touched:connect(function(character)
	if debounce then
		debounce = false
		local Player = game.Players:FindFirstChild(character.Parent.Name)
		local leaderstats = Player:FindFirstChild("leaderstats")
		local Cash = leaderstats:FindFirstChild("Cash")
		if Player and leaderstats and Cash then
			Cash.Value = Cash.Value + 10
			for i,v in pairs (Admins) do
				if Player.userId == Admins[i] or Player.Name:sub(1,6) == "Player" or game:GetService("GamePassService"):PlayerHasPass(Player,id) then
					Cash.Value = Cash.Value + 10
					break
				end
			end
		end
	end
	wait(5)
	debounce = true
end)

1 comment

0

Try setting debounce to true within the if statement.

1 answer

✓ Accepted answer

You can also look Here

exemple:

Part = workspace.Part
debounce = true

Part.Touched:connect(function(hit)
	if not debounce then return end
	debounce = false
	print("Hello")
	wait(1)
	debounce = true
end)

Fix:

Admins = {36491121,32441993,37983438}
id = 232590627
debounce = true
script.Parent.touched:connect(function(character)
    if not debounce then return end
        debounce = false
        local Player = game.Players:FindFirstChild(character.Parent.Name)
        local leaderstats = Player:FindFirstChild("leaderstats")
        local Cash = leaderstats:FindFirstChild("Cash")
        if Player and leaderstats and Cash then
            Cash.Value = Cash.Value + 10
            for i,v in pairs (Admins) do
                if Player.userId == Admins[i] or Player.Name:sub(1,6) == "Player" or game:GetService("GamePassService"):PlayerHasPass(Player,id) then
                    Cash.Value = Cash.Value + 10
                    break
                end
            end
        end
    end
    wait(5)
    debounce = true
end)

If its not work its maybe an other error in your script.

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