Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local ds = game:GetService("DataStoreService"):GetDataStore("SaveData")
- game.Players.PlayerAdded:Connect(function(plr)
- local leaderstats = Instance.new("Folder",plr)
- leaderstats.Name = "leaderstats"
- local Stage = Instance.new("IntValue",leaderstats)
- Stage.Name = "Stage"
- wait()
- local plrkey = "id"..plr.userId
- local save1 = plr.leaderstats.Stage
- local GetSaved = ds:GetAsync(plrkey)
- if GetSaved then
- save1.Value = GetSaved[1]
- else
- local NumberForSaving = {save1.Value}
- ds:GetAsync(plrkey, NumberForSaving)
- end
- end)
- game.Players.PlayerRemoving:Connect(function(plr)
- ds:SetAsync("id"..plr.userId,{plr.leaderstats.Stage.Value})
- end)
- game.Players.PlayerAdded:Connect(function(plr)
- plr.CharacterAdded:Connect(function(char)
- local Checkpoints = workspace:WaitForChild("Checkpoints"):GetChildren()
- for i = 1, #Checkpoints do
- Checkpoints[i].Touched:Connect(function(hit)
- local humanoid = hit.Parent:FindFirstChild("Humanoid")
- if not humanoid then return end
- local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
- if Checkpoints[i].Stage.Value < Player.leaderstats.Stage.Value then return end
- Player.leaderstats.Stage.Value = Checkpoints[i].Stage.Value
- end)
- end
- plr.Character.Humanoid.Died:Connect(function()
- wait(game.Players.RespawnTime + 0.0001)
- plr.Character.Head.CFrame = game.Workspace.Checkpoints:WaitForChild(plr.leaderstats.Stage.Value).CFrame + Vector3.new(0,8,0)
- end)
- end)
- end)
Add Comment
Please, Sign In to add comment