Advertisement
HowToRoblox

ObbyHandler

May 18th, 2020 (edited)
4,892
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.88 KB | None | 0 0
  1. local dss = game:GetService("DataStoreService")
  2. local obbyDS = dss:GetDataStore("ObbyData")
  3.  
  4. local checkpoints = workspace.Checkpoints
  5.  
  6.  
  7. game.Players.PlayerAdded:Connect(function(plr)
  8.    
  9.     local obbyData = obbyDS:GetAsync(plr.UserId .. "-obbyStageProgress")
  10.    
  11.     local ls = Instance.new("Folder")
  12.     ls.Name = "leaderstats"
  13.     ls.Parent = plr
  14.    
  15.     local stage = Instance.new("StringValue")
  16.     stage.Name = "Stage"
  17.     stage.Value = obbyData or 1
  18.     stage.Parent = ls
  19.    
  20.     local char = plr.Character or plr.CharacterAdded:Wait()
  21.    
  22.     char:waitForChild("HumanoidRootPart"):GetPropertyChangedSignal("CFrame")
  23.    
  24.     char:WaitForChild("HumanoidRootPart").CFrame = checkpoints[stage.Value].CFrame
  25.    
  26.     char.Humanoid.Touched:Connect(function(touch)
  27.        
  28.         if touch.Parent == checkpoints then
  29.             if (tonumber(touch.Name) and tonumber(touch.Name) > tonumber(stage.Value)) or touch.Name == "End" then
  30.                 stage.Value = touch.Name
  31.                
  32.                 pcall(function()
  33.                    
  34.                     obbyDS:SetAsync(plr.UserId .. "-obbyStageProgress", plr.leaderstats.Stage.Value)
  35.                 end)
  36.             end
  37.         end
  38.     end)
  39.    
  40.     plr.CharacterAdded:Connect(function(char)
  41.        
  42.         local hrp = char:WaitForChild("HumanoidRootPart")      
  43.         local humanoid = char:WaitForChild("Humanoid")
  44.        
  45.         hrp:GetPropertyChangedSignal("CFrame"):Wait()
  46.        
  47.         hrp.CFrame = checkpoints[stage.Value].CFrame
  48.        
  49.         humanoid.Touched:Connect(function(touch)
  50.            
  51.             if touch.Parent == checkpoints then
  52.                 if (tonumber(touch.Name) and tonumber(touch.Name) > tonumber(stage.Value)) or touch.Name == "End" then
  53.                     stage.Value = touch.Name
  54.                    
  55.                     pcall(function()
  56.                        
  57.                         obbyDS:SetAsync(plr.UserId .. "-obbyStageProgress", plr.leaderstats.Stage.Value)
  58.                     end)
  59.                 end
  60.             end
  61.         end)
  62.     end)   
  63. end)
  64.  
  65.  
  66. game.Players.PlayerRemoving:Connect(function(plr)
  67.    
  68.     pcall(function()
  69.        
  70.         obbyDS:SetAsync(plr.UserId .. "-obbyStageProgress", plr.leaderstats.Stage.Value)
  71.     end)
  72. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement