Hello, I’m wanting to make a collectable “Coin” with a shop system, the problem is, that, the shop system has a leaderboard inside of it, to get money, if I use commands, when I buy something from the shop, the money that I added disappear, for example, I give myself 1000$, I had 250 before, now I have 1250$, if I buy a weapon that has 250$ as price, when I buy it, that 1000$ disappears and my money gets to 0 (Bc the only money that was in my stats was 250), its like the system doesnt count when I add that money, same with the coins (the stats is the same as the one with commands), when I collect one, it goes to the stats, but dissapears when I buy something, same with a currency shop (same as coins and commands), I buy 100$, it gets to stats, but dissapears when I buy something, this was from a tutorial, and the only thing that gives me money and works is the system the guy made, its a block that has this script:
local DataStore2 = require(game.ServerScriptService:WaitForChild("MainModule"))
debounce = false
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") and debounce == false then
debounce = true
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
local MoneyData = DataStore2("Money", plr)
MoneyData:Increment(100)
debounce = false
end
end)
when I touch the block, it gives me money, what I want, is to know where or how should I modify this script of my coin when I get the money:
waittime = 15 -- Time Between each hit
amnt = 30 --how much you get for it
function onTouched(part)
local h = part.Parent:findFirstChild("Humanoid")
if (h~=nil) then
local thisplr = game.Players:findFirstChild(h.Parent.Name)
if (thisplr~=nil) then
local stats = thisplr:findFirstChild("leaderstats")
if (stats~=nil) then
local score = stats:findFirstChild("Money")
if (score~=nil) then
score.Value = score.Value + amnt
end
end
end
script.Parent.Transparency = 1
script.Disabled = true
wait(waittime)
script.Parent.Transparency = 0
script.Disabled = false
end
end
script.Parent.Touched:connect(onTouched)
If someone knows how where is the problem, please inform me. Thanks for reading