How to make a Teleportation function#2

Hi everyone I’m currently working on a Tool Ability System and I need an Ability that teleports the player if tool is activated to the MouseButton or sth. with a Cooldown of 10 Seconds Ik I may be annoying but I don’t really know how to do these abilities I even searched up on other platforms.

1 Like
--LocalScript parented to the tool

local player:Player = game:GetService("Players").LocalPlayer
local character:Model = player.Character or player.CharacterAdded:Wait()

local rootPart:Part = character:WaitForChild("HumanoidRootPart")

local tool:Tool = script.Parent

local function onToolActivated()
    rootPart.CFrame += rootPart.CFrame.LookVector * 5
end

tool.Activated:Connect(onToolActivated)

You can also use raycasting to stop the player going through walls.

2 Likes

you it works but how can I use this raycasting thing

You would just cast a ray beforehand to ensure they don’t go through a wall.

local params:RaycastParams = RaycastParams.new()
params.FilterDescendantsInstances = {character}
params.FilterType = Enum.RaycastFilterType.Exclude

--then, when you need it:
local target = nil
local origin:Vector3 = rootPart.CFrame.Position
local direction:Vector3 = rootPart.CFrame.LookVector * 5

local hit:RaycastResult = workspace:Raycast(origin, direction, params)

if hit then
    target = CFrame.new(hit.Position) * CFrame.Angles(rootPart.CFrame:ToEularAnglesXYZ()) :: CFrame
else
    target = rootPart.CFrame + (rootPart.CFrame.LookVector * 5)
end

rootPart.CFrame = target

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.