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

If a gave money from the console it saved. But if the money is came from a tool not saving?

Asked by 4 years ago
Edited 4 years ago

I am making a Simulator game but i just make a Datastore and publish the game. Then i tried to give my self a 100000 of money from the console i quit then i joined again, it saved. Then i try to make my Money to 0 again and click the tool for money. I quit then i joined its not saving. Why?

CODE:

BitcoinData = game:GetService("DataStoreService"):GetDataStore("BitcoinData")
MoneyData = game:GetService("DataStoreService"):GetDataStore("MoneyData")

game.Players.PlayerAdded:Connect(function(plr)
    local LB = Instance.new("Folder", plr)
    LB.Name = "leaderstats"

    local p = Instance.new("IntValue", LB)
    p.Name = "Bitcoin"
    p.Value = BitcoinData:GetAsync(plr.UserId)

    local r = Instance.new("IntValue", LB)
    r.Name = "Money"
    r.Value = MoneyData:GetAsync(plr.UserId)

    local bitcoinData, moneyData

    local success, errormessage = pcall(function()
        bitcoinData = BitcoinData:GetAsync("Bitcoin-"..plr.UserId)
        moneyData = MoneyData:GetAsync("Money-"..plr.UserId)
    end)

    if success then
        if bitcoinData then
            p.Value = bitcoinData
            r.Value = moneyData
        end
    end
end)

game.Players.PlayerRemoving:Connect(function(plr)
    local success, errormessage = pcall(function()
        BitcoinData:SetAsync("Bitcoin-"..plr.UserId,plr.leaderstats.Bitcoin.Value)
        MoneyData:SetAsync("Money-"..plr.UserId,plr.leaderstats.Money.Value)
    end)
end)

1 answer

Log in to vote
0
Answered by 4 years ago

Make sure that this "Tool" increase the value of "Money" on the server side

if you are doing it using a localscript, it will increase the "money" locally, but the server version of "money" will still be the same

Ad

Answer this question