I have a datastore, I started with 5,000 Cash, then I went into game and I got to about 5,500, then I rejoined with only 5,011
This is my script
local DataStore = game:GetService("DataStoreService")
local ds = DataStore:GetDataStore("CashSaveSystem")
local part = game.Workspace.Part
game.Players.PlayerAdded:connect(function(player)
local leader = Instance.new("Folder",player)
leader.Name = "leaderstats"
local Cash = Instance.new("IntValue",leader)
Cash.Name = "Money"
Cash.Value = ds:GetAsync(player.UserId) or 5000
ds:SetAsync(player.UserId, Cash.Value)
Cash.Changed:connect(function()
ds:SetAsync(player.UserId, Cash.Value)
end)
end)
game.Players.PlayerRemoving:connect(function(player)
ds:SetAsync(player.UserId, player.leaderstats.Cash.Value)
end)
function onMouseClick(player)
local Cash = player.leaderstats.Money
Cash.Value = Cash.Value + 1
end
part.ClickDetector.MouseClick:connect(onMouseClick)