Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local SaveData = game:GetService("DataStoreService"):GetDataStore("Lives")
- game.Players.PlayerAdded:Connect(function(Player)
- local Character = Player.Character or Player.CharacterAdded:Wait()
- local Humanoid = Character.Humanoid
- local SystemFolder = Instance.new("Folder",Player)
- SystemFolder.Name = "SystemFolder"
- local Lives = Instance.new("IntValue",SystemFolder)
- Lives.Value = 3
- Lives.Name = "Lives"
- local Times = Instance.new("IntValue", SystemFolder)
- Times.Value = os.time()
- Times.Name = "Times"
- local Success, Value = pcall(function()
- return SaveData:GetAsync(Player.UserId)
- end)
- local function LivesChanging()
- if Lives.Value == 0 then Player.Character.HumanoidRootPart.CFrame = workspace.NoLifePart.CFrame end
- if Lives.Value < 0 then
- Lives.Value = 0
- elseif Lives.Value > 15 then
- Lives.Value = 15
- end
- end
- local function CheckTime()
- Times.Value = Times.Value + 1
- if Times.Value >= 3600 then
- Times.Value = 0
- Lives.Value = Lives.Value + 1
- end
- end
- LivesChanging()
- Lives.Changed:Connect(LivesChanging)
- if Success then
- if Value then
- Lives.Value = Value[1]
- Times.Value = Value[2]
- else
- Times.Value = 0
- Lives.Value = 3
- end
- end
- spawn(function()
- while wait(1) do
- CheckTime()
- end
- end)
- end)
- game.Players.PlayerRemoving:Connect(function(Player)
- local StatTable = {
- Player:WaitForChild("SystemFolder").Lives.Value;
- Player:WaitForChild("SystemFolder").Times.Value;
- }
- local Success, Error = pcall(function()
- return SaveData:SetAsync(Player.UserId, StatTable)
- end)
- if Error then
- print(Error)
- end
- end)
- game:BindToClose(function()
- for i,players in pairs(game.Players:GetPlayers()) do
- local StatTable = {
- players:WaitForChild("SystemFolder").Lives.Value;
- players:WaitForChild("SystemFolder").Times.Value;
- }
- local Success, Error = pcall(function()
- return SaveData:SetAsync(players.UserId, StatTable)
- end)
- if Error then
- print(Error)
- end
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement