krLuCiEzkr

Checkpoint Pad Script

Nov 10th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. local Players = game:GetService("Players")
  2. local ServerStorage = game:GetService("ServerStorage")
  3.  
  4. local checkpoint = script.Parent
  5.  
  6. function onTouched(hit)
  7. if hit and hit.Parent and hit.Parent:FindFirstChildOfClass("Humanoid") then
  8. local player = Players:GetPlayerFromCharacter(hit.Parent)
  9. local checkpointData = ServerStorage:FindFirstChild("CheckpointData")
  10. if not checkpointData then
  11. checkpointData = Instance.new("Folder")
  12. checkpointData.Name = "CheckpointData"
  13. checkpointData.Parent = ServerStorage
  14. end
  15.  
  16. local userIdString = tostring(player.UserId)
  17. local checkpointValue = checkpointData:FindFirstChild(userIdString)
  18. if not checkpointValue then
  19. checkpointValue = Instance.new("ObjectValue")
  20. checkpointValue.Name = userIdString
  21. checkpointValue.Parent = checkpointData
  22.  
  23. player.CharacterAdded:connect(function(character)
  24. wait()
  25. local storedCheckpoint = ServerStorage.CheckpointData[userIdString].Value
  26. character:MoveTo(storedCheckpoint.Position + Vector3.new(math.random(-4, 4), 4, math.random(-4, 4)))
  27. end)
  28. end
  29.  
  30. checkpointValue.Value = checkpoint
  31. end
  32. end
  33.  
  34. checkpoint.Touched:Connect(onTouched)
Add Comment
Please, Sign In to add comment