blakehelton

Checkpoint Script

Jul 29th, 2021
775
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local spawn = script.Parent
  2. spawn.Touched:connect(function(hit)
  3.     if hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid") then
  4.         local player = game.Players:GetPlayerFromCharacter(hit.Parent)
  5.         local checkpointData = game.ServerStorage:FindFirstChild("CheckpointData")
  6.         if not checkpointData then
  7.             checkpointData = Instance.new("Model", game.ServerStorage)
  8.             checkpointData.Name = "CheckpointData"
  9.         end
  10.  
  11.         local checkpoint = checkpointData:FindFirstChild(tostring(player.userId))
  12.         if not checkpoint then
  13.             checkpoint = Instance.new("ObjectValue", checkpointData)
  14.             checkpoint.Name = tostring(player.userId)
  15.  
  16.             player.CharacterAdded:connect(function(character)
  17.                 wait()
  18.                 local newUser = tostring(player.userId)
  19.                 local newData = game.ServerStorage.CheckpointData[newUser].Value.CFrame
  20.                 local newCheckpoint = newData + Vector3.new(0, 4, 0)
  21.                 character:WaitForChild("HumanoidRootPart").CFrame = newCheckpoint
  22.             end)
  23.         end
  24.         checkpoint.Value = spawn
  25.     end
  26. end)
RAW Paste Data