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

My shop script for my gui only works once and takes all my money even with a debounce?

Asked by 5 years ago
Edited 5 years ago
local debounce = false

local moneybounce = false

game.ReplicatedStorage.place1event.OnServerEvent:Connect(function(player)

    if player.leaderstats.Money.Value >= 5 then

        if not debounce then

            local char = player.Character.Humanoid

            debounce = true

            if not moneybounce then

                moneybounce = true

                player.leaderstats.Money.Value = player.leaderstats.Money.Value - 5

                moneybounce = false

            end

            char.WalkSpeed = char.WalkSpeed + 5

            print("Purchase Successful!")

            debounce = false

        end

    else

        print("Too Poor!")

    end



end)
0
Could you please redo the boxes that has the script in it, parts of it aren't in the box. superawesome113 112 — 5y
0
should be fixed now JagoRBX 7 — 5y

2 answers

Log in to vote
0
Answered by 5 years ago

after money bounce = true and debounce = true add a wait(time in here) that way they cant click it again the reason it takes all the money is because the function runs several times so i would do

local debounce = false

local moneybounce = false

game.ReplicatedStorage.place1event.OnServerEvent:Connect(function(player)

    if player.leaderstats.Money.Value >= 5 then

        if not debounce then

            local char = player.Character.Humanoid

            debounce = true
            wait(1)

            if not moneybounce then

                moneybounce = true
                wait(1)

                player.leaderstats.Money.Value = player.leaderstats.Money.Value - 5

                moneybounce = false

            end

            char.WalkSpeed = char.WalkSpeed + 5

            print("Purchase Successful!")

            debounce = false

        end

    else

        print("Too Poor!")

    end



end)
Ad
Log in to vote
0
Answered by 5 years ago

You should add a

wait(1)

after the money deduction part. The moneybounce is useless unless there's a wait.

0
Thanks! JagoRBX 7 — 5y

Answer this question