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

Why does my debounce not work? {SOLVED} [closed]

Asked by 9 years ago

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)
0
Try setting debounce to true within the if statement. GoldenPhysics 474 — 9y

Locked by fahmisack123, FearMeIAmLag, SanityMan, and adark

This question has been locked to preserve its current state and prevent spam and unwanted comments and answers.

Why was this question closed?

1 answer

Log in to vote
2
Answered by 9 years ago

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.

Ad