Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local CashDataStore = game:GetService("DataStoreService"):GetDataStore("Cash")
- game.Players.PlayerAdded:Connect(function(player)
- local previousData = CashDataStore:GetAsync(player.UserId)
- local Cash
- if previousData ~= nil then
- Cash = previousData
- else
- Cash = 0
- CashDataStore:SetAsync(player.UserId, Cash)
- end
- local CashValue = Instance.new("NumberValue", player)
- CashValue.Name = "Cash"
- CashValue.Value = Cash
- end)
- game:BindToClose(function()
- for i,player in pairs(game.Players:GetPlayers()) do
- local value = player.Cash.Value
- CashDataStore:SetAsync(player.UserId, value)
- print("Saved data for "..player.Name)
- end
- end)
- game.Players.PlayerRemoving:Connect(function(player)
- local value = player.Cash.Value
- if value ~= nil then
- print("Found data to save for "..player.Name.."!")
- CashDataStore:SetAsync(player.UserId, value)
- print("Saved data for "..player.Name)
- else
- print("Did not manage to find data to save for "..player.Name.."!")
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement