3DCreator

Main Script

Feb 28th, 2021 (edited)
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.46 KB | None | 0 0
  1. local ds = game:GetService("DataStoreService"):GetDataStore("SaveData")
  2. game.Players.PlayerAdded:Connect(function(plr)
  3.     local leaderstats = Instance.new("Folder",plr)
  4.     leaderstats.Name = "leaderstats"
  5.     local Stage = Instance.new("IntValue",leaderstats)
  6.     Stage.Name = "Stage"
  7.     wait()
  8.     local plrkey = "id"..plr.userId
  9.     local save1 = plr.leaderstats.Stage
  10.     local GetSaved = ds:GetAsync(plrkey)
  11.     if GetSaved then
  12.         save1.Value = GetSaved[1]
  13.     else
  14.         local NumberForSaving = {save1.Value}
  15.         ds:GetAsync(plrkey, NumberForSaving)
  16.     end
  17. end)
  18.  
  19. game.Players.PlayerRemoving:Connect(function(plr)
  20.     ds:SetAsync("id"..plr.userId,{plr.leaderstats.Stage.Value})
  21. end)
  22.  
  23. game.Players.PlayerAdded:Connect(function(plr)
  24.     plr.CharacterAdded:Connect(function(char)
  25.         local Checkpoints = workspace:WaitForChild("Checkpoints"):GetChildren()
  26.         for i = 1, #Checkpoints do
  27.             Checkpoints[i].Touched:Connect(function(hit)
  28.                 local humanoid = hit.Parent:FindFirstChild("Humanoid")
  29.                 if not humanoid then return end
  30.                 local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
  31.                 if Checkpoints[i].Stage.Value < Player.leaderstats.Stage.Value then return end
  32.                 Player.leaderstats.Stage.Value = Checkpoints[i].Stage.Value
  33.             end)
  34.         end
  35.         plr.Character.Humanoid.Died:Connect(function()
  36.             wait(game.Players.RespawnTime + 0.0001)
  37.             plr.Character.Head.CFrame = game.Workspace.Checkpoints:WaitForChild(plr.leaderstats.Stage.Value).CFrame + Vector3.new(0,8,0)
  38.         end)
  39.     end)
  40. end)
Add Comment
Please, Sign In to add comment