The 9th and 11th click removes 0.02 from the bag instead of 0.01

Im running into the issue that on those clicks it removes 0.02 from the bag.
It only happens on those 2.
i have no idea why

– The script that fires the event

local Events = game.ReplicatedStorage.Events
script.Parent.Parent.MainFrame.GetMoneyButton.Activated:Connect(function()
	Events.GetMoney:FireServer()
end)```

-- The script that gives the money
```local Events = game.ReplicatedStorage.Events

game.Players.PlayerAdded:Connect(function(player)
    local money = player:WaitForChild("leaderstats"):WaitForChild("Money")
    local PStats = player:WaitForChild("Stats")
    local PlayerBag = PStats:WaitForChild("PlayerBag")
    local PlayerPower = PStats:WaitForChild("PlayerPower")
    local RankMulti = PStats:WaitForChild("RankMulti")
    local TierMulti = PStats:WaitForChild("TierMulti")

    local debounce = false

    local function GetMoney()
        if not debounce then
            debounce = true
            local ToGive = (((PlayerPower.Value / 100) * RankMulti.Value) * TierMulti.Value)
            if PlayerBag.Value == 0 then
                print("You don't have enough money in your bag to receive money.")
            elseif PlayerBag.Value < ToGive then
                local remainingMoney = PlayerBag.Value
                money.Value = money.Value + remainingMoney
                PlayerBag.Value = PlayerBag.Value - remainingMoney
                print("You don't have enough money in your bag to receive the full amount. Received remaining money: $" .. string.format("%.2f", remainingMoney))
            else
                PlayerBag.Value = PlayerBag.Value - ToGive
                money.Value = money.Value + ToGive
                print("Received money: $" .. string.format("%.2f", ToGive))
            end
            task.wait(0.05)
            debounce = false
        end
    end

    if Events.GetMoney then
        Events.GetMoney.OnServerEvent:Connect(GetMoney)
    end
end)

local debounce should be declared earlier in your script, it currently does nothing

i did do that before. but i changed it later

Hello, I am not sure If this helps but you should try:

you should define debounce outside of the GetMoney function so that its state is preserved across multiple calls I beilve.

local Events = game.ReplicatedStorage.Events

game.Players.PlayerAdded:Connect(function(player)
    local money = player:WaitForChild("leaderstats"):WaitForChild("Money")
    local PStats = player:WaitForChild("Stats")
    local PlayerBag = PStats:WaitForChild("PlayerBag")
    local PlayerPower = PStats:WaitForChild("PlayerPower")
    local RankMulti = PStats:WaitForChild("RankMulti")
    local TierMulti = PStats:WaitForChild("TierMulti")

    local debounce = false

    local function GetMoney()
        if not debounce then
            debounce = true
            local ToGive = (((PlayerPower.Value / 100) * RankMulti.Value) * TierMulti.Value)
            if PlayerBag.Value == 0 then
                print("You don't have enough money in your bag to receive money.")
            elseif PlayerBag.Value < ToGive then
                local remainingMoney = PlayerBag.Value
                money.Value = money.Value + remainingMoney
                PlayerBag.Value = PlayerBag.Value - remainingMoney
                print("You don't have enough money in your bag to receive the full amount. Received remaining money: $" .. string.format("%.2f", remainingMoney))
            else
                PlayerBag.Value = PlayerBag.Value - ToGive
                money.Value = money.Value + ToGive
                print("Received money: $" .. string.format("%.2f", ToGive))
            end
            task.wait(0.05)
            debounce = false
        end
    end

    if Events.GetMoney then
        Events.GetMoney.OnServerEvent:Connect(GetMoney)
    end
end)

i had it outside before. but changed it. idk why