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

If I click fast twice , Why do I end up with -10 coins?

Asked by
phxtn 154
6 years ago

local script:

script.Parent.MouseButton1Click:Connect(function()
    local cost = 10
    local player = game.Players.LocalPlayer
    local leaderstats = player:WaitForChild("leaderstats")
    if leaderstats then
        local coins = leaderstats:WaitForChild("Coins")
        if coins then
                if coins.Value >= cost then
                        game.ReplicatedStorage:WaitForChild("Blue effect coins remove"):FireServer()
                        game.ReplicatedStorage:WaitForChild("Blue effect"):FireServer()
                end
        end
    end

If I click fast then it will become -10 or -20 like that

script:

local BlueEffect = Instance.new("RemoteEvent", game.ReplicatedStorage)
local Blueeffectcoinsremove = Instance.new("RemoteEvent", game.ReplicatedStorage)
BlueEffect.Name = "Blue effect"
Blueeffectcoinsremove.Name = "Blue effect coins remove"
BlueEffect.OnServerEvent:Connect(function(plr)
        local Sparkles = Instance.new("Sparkles", plr.Character.LowerTorso)
        Sparkles.Name = "BlueEffect"
        Sparkles.SparkleColor = Color3.new(0,0,255)
end)

Blueeffectcoinsremove.OnServerEvent:Connect(function(pl)
    pl.leaderstats.Coins.Value = pl.leaderstats.Coins.Value - 10
end)
0
Add a debounce, because when you click it the first time, the function is executing. The first event hasn't gone through all of it, so When you click it again. it thinks that you still have more than 9 coins: http://wiki.roblox.com/index.php?title=Debounce thesit123 509 — 6y
0
^ SinatraKoslov 27 — 6y
0
Never rely on validation done on the client side. Check the cash on the server side before giving anything out. User#5423 17 — 6y

Answer this question