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

Why is this function running 16 times even with debounce?

Asked by 3 years ago

I've got debounce and this function's running 16 times each time

game.Players.PlayerAdded:Connect(function(player)
local MoneyBoard = Instance.new("Folder")
MoneyBoard.Name = "leaderstats"
    local Money = Instance.new("IntValue", MoneyBoard)
    Money.Name = "Money"
Money.Value = 0
    MoneyBoard.Parent = player
    local db = false

    game.Workspace.MoneyCollector.Touched:Connect(function(hit)
        if not db then
            local db = true
        if hit.Parent:FindFirstChild("HumanoidRootPart") then
            game.Players:GetPlayerFromCharacter(hit.Parent)
            if db == true then
                print(5)
            end
            if player then
                while Money.Value <30000000 do
                    Money.Value = Money.Value + 1000
                        wait(2)
                        end
                end
            end
        end
    end)
end)
local db = false

1 answer

Log in to vote
0
Answered by 3 years ago

Remove local from line 12

db = true

Local causes the variable to be changed only within the if statement.

Ad

Answer this question