Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local LivesDataStore = game:GetService("DataStoreService"):GetDataStore("Lives")
- game.Players.PlayerAdded:Connect(function(player)
- local PreviousData = LivesDataStore:GetAsync(player.UserId)
- local Lives
- if PreviousData ~= nil then
- Lives = PreviousData
- else
- Lives = script.numberLives.Value
- LivesDataStore:SetAsync(player.UserId, Lives)
- end
- local LivesValue = Instance.new("NumberValue", player)
- LivesValue.Name = "Lives"
- LivesValue.Value = Lives
- end)
- game:BindToClose(function()
- for i,player in pairs(game.Players:GetPlayers()) do
- local value = player.Lives.Value
- LivesDataStore:SetAsync(player.UserId, value)
- print("Saved data for "..player.Name)
- end
- end)
- game.Players.PlayerRemoving:Connect(function(player)
- local value = player.Lives.Value
- if value ~= nil then
- print("Found data to save for "..player.Name.."!")
- LivesDataStore: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