Advertisement
PeperVr

(ROBLOX) Checkpoint Teleporter

Jun 27th, 2024 (edited)
20
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.18 KB | None | 0 0
  1. -- "E" to teleport to your checkpoint "R" to set the checkpoint to your desired location.
  2. -- Variables
  3. local player = game.Players.LocalPlayer
  4. local mouse = player:GetMouse()
  5. local userInputService = game:GetService("UserInputService")
  6.  
  7. local checkpointPosition = nil
  8. local indicatorPart = nil
  9.  
  10. -- Function to handle teleportation to look direction
  11. local function teleportToLookDirection()
  12. local ray = Ray.new(
  13. player.Character.Head.Position,
  14. (mouse.Hit.p - player.Character.Head.Position).unit * 1000 -- Ray length
  15. )
  16. local hit, position = workspace:FindPartOnRay(ray, player.Character)
  17.  
  18. -- Teleport the player
  19. if hit then
  20. player.Character:SetPrimaryPartCFrame(CFrame.new(position))
  21. end
  22. end
  23.  
  24. -- Function to set checkpoint and update indicator
  25. local function setCheckpoint()
  26. checkpointPosition = player.Character.PrimaryPart.CFrame.Position
  27. print("Checkpoint set!")
  28.  
  29. -- Create or update indicator part
  30. if indicatorPart then
  31. indicatorPart:Destroy()
  32. end
  33.  
  34. -- Create Cylinder to act as the indicator
  35. indicatorPart = Instance.new("Part")
  36. indicatorPart.Size = Vector3.new(8, 0.2, 8)
  37. indicatorPart.Position = Vector3.new(checkpointPosition.X, checkpointPosition.Y + 1, checkpointPosition.Z)
  38. indicatorPart.Color = Color3.new(0, 1, 0) -- Green color
  39. indicatorPart.Material = Enum.Material.Neon
  40. indicatorPart.Anchored = true
  41. indicatorPart.CanCollide = false
  42. indicatorPart.Shape = Enum.PartType.Cylinder
  43. indicatorPart.Parent = workspace
  44. end
  45.  
  46. -- Connect key press events
  47. userInputService.InputBegan:Connect(function(input, isProcessed)
  48. if not isProcessed then
  49. if input.KeyCode == Enum.KeyCode.E then
  50. if checkpointPosition then
  51. -- Teleport to checkpoint if it exists
  52. player.Character:SetPrimaryPartCFrame(CFrame.new(checkpointPosition))
  53. else
  54. -- Teleport to look direction if no checkpoint set
  55. teleportToLookDirection()
  56. end
  57. elseif input.KeyCode == Enum.KeyCode.R then
  58. -- Set checkpoint
  59. setCheckpoint()
  60. end
  61. end
  62. end)
  63.  
Advertisement
Comments
  • PeperVr
    148 days
    Comment was deleted
Add Comment
Please, Sign In to add comment
Advertisement