So for example u click X and it teleports u 6 studs in front
3 Likes
First, you need to detect input. You could use either UserInputService or ContextActionService on the client to do this.
Next, you need to move the character. You could try manipulating the position of the HumanoidRootPart
to do this.
local player = game:GetService("Players").LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local hrp = char:WaitForChild("HumanoidRootPart")
hrp.CFrame = CFrame.new(hrp.CFrame.Position + (hrp.CFrame.LookVector * 5))
5 Likes
Usually, it’s beneficial to provide a snippet of your attempted code to demonstrate your initiative in tackling the problem. However, since this task is relatively straightforward, it presents a good opportunity for learning.
-- Define the key that will trigger the teleportation
local teleportKey = Enum.KeyCode.X -- Change this to the key you want to use for teleportation
-- Define the distance the player will be teleported
local teleportDistance = 6 -- Change this value to adjust the distance you want to teleport
-- Connect a function to the InputBegan event of the UserInputService
game:GetService("UserInputService").InputBegan:Connect(function(input)
-- Check if the input is from the keyboard
if input.UserInputType == Enum.UserInputType.Keyboard then
-- Check if the pressed key matches the teleport key
if input.KeyCode == teleportKey then
-- Get the local player
local player = game.Players.LocalPlayer
-- Check if the player exists
if player then
-- Get the character of the player
local character = player.Character
-- Check if the character exists
if character then
-- Get the HumanoidRootPart of the character
local humanoidRootPart = character:FindFirstChild("HumanoidRootPart")
-- Check if the HumanoidRootPart exists
if humanoidRootPart then
-- Calculate the new position to teleport to
local currentRotation = humanoidRootPart.CFrame - humanoidRootPart.Position
local newPosition = humanoidRootPart.Position + (currentRotation.LookVector * teleportDistance)
-- Teleport the character to the new position
humanoidRootPart.CFrame = CFrame.new(newPosition)
end
end
end
end
end
end)
6 Likes
Thanks! it worked i was making teleport ability for my rng game aura and yours worked!
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.