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

issue with leader stat, and coins?

Asked by 3 years ago

So I have a leadersat in a folder called coins(folder is called Susy) and the issue is with the coins, Once I click on the gui to buy the item it subtracts from the leaderstat value, then as soon as I pick up another coin it adds instead of +1 coin it adds + 11, here is the code for the shop



local plr = game:GetService('Players').LocalPlayer script.Parent.MouseButton1Click:Connect(function() if plr.Susy.Coins.Value > 9 then local clone = game.ReplicatedStorage.GravityCoil:Clone() clone.Parent = plr.Backpack plr.Susy.Coins.Value = plr.Susy.Coins.Value - 5 plr.Susy.Coins.Value -= 5 script.Parent.Parent.BruhV2.Visible = true wait(1) script.Parent.Parent.BruhV2.Visible = false wait(1) script.Parent.Parent.Visible = false script.Parent.Parent.Parent.TextButton.Visible = true script.Parent.Parent.Parent.DISPLAYCOINS.Visible = true else plr.leaderstats.Wins.Value = plr.leaderstats.Wins.Value - 0 script.Parent.Parent.Bruh.Visible = true wait(2) script.Parent.Parent.Bruh.Visible = false end end)

And here is the code for the coin ~~~~~~~~~~~~~~~~~

local player = game.Players.LocalPlayer

script.Parent.Touched:Connect(function(hit) game.Workspace.Misc.CoinPickup:Play() local plr = game.Players:GetPlayerFromCharacter(hit.Parent) if plr then plr.Susy.Coins.Value += 1 script.Parent:Destroy()

end

end)

0
can you please fix that last code block? can't really understand the code like that PaleNoobs 37 — 3y

2 answers

Log in to vote
0
Answered by 2 years ago
Edited 2 years ago

Ok, I think it might be because your not using debounce, because of this, the coin will detect that multiple parts of the characters body is touching the coin. Try this

local player = game.Players.LocalPlayer
local debounce = false

script.Parent.Touched:Connect(function(hit)
 game.Workspace.Misc.CoinPickup:Play() 
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
 if plr then
if debounce == false then
debounce = true
plr.Susy.Coins.Value += 1 script.Parent:Destroy()
end
end
debounce = false
end)

I'm not sure if this will help but I hope it does because this happened to me before.

Ad
Log in to vote
0
Answered by 2 years ago

Using debounce will resolve this issue

local player = game.Players.LocalPlayer
local db = false
script.Parent.Touched:Connect(function(hit) 
    if not db then
        game.Workspace.Misc.CoinPickup:Play() 
        local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
        if plr then plr.Susy.Coins.Value += 1 script.Parent:Destroy() end
        db = true
        wait(2)
        db = false -- I think you can remove this line and the wait since it will destroy the part + the script anyway.
    end
end)
0
sorry im late AProgrammR 398 — 2y

Answer this question