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)
