Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Debounce | having trouble :( ?

Asked by
FiredDusk 1466 Moderation Voter
8 years ago
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

Log in to vote
1
Answered by
Legojoker 345 Moderation Voter
8 years ago

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)
Ad

Answer this question