Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- "E" to teleport to your checkpoint "R" to set the checkpoint to your desired location.
- -- Variables
- local player = game.Players.LocalPlayer
- local mouse = player:GetMouse()
- local userInputService = game:GetService("UserInputService")
- local checkpointPosition = nil
- local indicatorPart = nil
- -- Function to handle teleportation to look direction
- local function teleportToLookDirection()
- local ray = Ray.new(
- player.Character.Head.Position,
- (mouse.Hit.p - player.Character.Head.Position).unit * 1000 -- Ray length
- )
- local hit, position = workspace:FindPartOnRay(ray, player.Character)
- -- Teleport the player
- if hit then
- player.Character:SetPrimaryPartCFrame(CFrame.new(position))
- end
- end
- -- Function to set checkpoint and update indicator
- local function setCheckpoint()
- checkpointPosition = player.Character.PrimaryPart.CFrame.Position
- print("Checkpoint set!")
- -- Create or update indicator part
- if indicatorPart then
- indicatorPart:Destroy()
- end
- -- Create Cylinder to act as the indicator
- indicatorPart = Instance.new("Part")
- indicatorPart.Size = Vector3.new(8, 0.2, 8)
- indicatorPart.Position = Vector3.new(checkpointPosition.X, checkpointPosition.Y + 1, checkpointPosition.Z)
- indicatorPart.Color = Color3.new(0, 1, 0) -- Green color
- indicatorPart.Material = Enum.Material.Neon
- indicatorPart.Anchored = true
- indicatorPart.CanCollide = false
- indicatorPart.Shape = Enum.PartType.Cylinder
- indicatorPart.Parent = workspace
- end
- -- Connect key press events
- userInputService.InputBegan:Connect(function(input, isProcessed)
- if not isProcessed then
- if input.KeyCode == Enum.KeyCode.E then
- if checkpointPosition then
- -- Teleport to checkpoint if it exists
- player.Character:SetPrimaryPartCFrame(CFrame.new(checkpointPosition))
- else
- -- Teleport to look direction if no checkpoint set
- teleportToLookDirection()
- end
- elseif input.KeyCode == Enum.KeyCode.R then
- -- Set checkpoint
- setCheckpoint()
- end
- end
- end)
Advertisement
Advertisement