Advertisement
Drvays

Obby Checkpoint Saving System

Jul 5th, 2022
8,019
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. local DataStoreService = game:GetService("DataStoreService")
  2. local DataStore = DataStoreService:GetDataStore("ObbyDataStore")
  3. local Checkpoints = game.Workspace:WaitForChild("Checkpoints"):GetChildren()
  4.  
  5. for i, checkpoint in pairs(Checkpoints) do
  6. checkpoint.TeamColor = game.Teams:FindFirstChild(checkpoint.Name).TeamColor
  7. checkpoint.BrickColor = game.Teams:FindFirstChild(checkpoint.Name).TeamColor
  8. end
  9.  
  10. game.Players.PlayerAdded:Connect(function(player)
  11. local data
  12. local success, errorMessage = pcall(function()
  13. data = DataStore:GetAsync(player.UserId.."stage")
  14. end)
  15. if success then
  16. if data then
  17. player.Team = game.Teams[data]
  18. else
  19. player.Team = game.Teams.Stage1
  20. end
  21. else
  22. player.Team = game.Teams.Stage1
  23. end
  24. player:LoadCharacter()
  25. end)
  26.  
  27. game.Players.PlayerRemoving:Connect(function(player)
  28. local success, errorMessage = pcall(function()
  29. DataStore:SetAsync(player.UserId.."stage", player.Team.Name)
  30. end)
  31. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement