Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

i cant get a teleport script to do what its meant to?

sorry about the title it wouldn't let me put anything else

right so i got 2 scripts off incaps the first one was this(this one works on its own)

function teleport()
    local char = game:GetService("Players").LocalPlayer.Character
    char.HumanoidRootPart.CFrame = CFrame.new(-185.8, 357.3, -569.6)

end

game:GetService("ContextActionService"):BindAction(
    "Teleport",
    teleport,
    false,
    Enum.KeyCode.E
)

and the second one was this

local dist = (char.HumanoidRootPart.Position - part.Position).magnitude

if dist <= 20 then -- make 20 bigger if you want more range, smaller for less.
    --do your code  
end 

to gather there this

local dist = (char.HumanoidRootPart.Position - part.Position).magnitude

if dist <= 20 then -- make 20 bigger if you want more range, smaller for less.
    function teleport()
    local char = game:GetService("Players").LocalPlayer.Character
    char.HumanoidRootPart.CFrame = CFrame.new(-185.8, 357.3, -569.6)

end

game:GetService("ContextActionService"):BindAction(
    "Teleport",
    teleport,
    false,
    Enum.KeyCode.E
)
end 

the point of them is to teleport a player when they click the E key in a rage of a part can someone please tell me how to use this script thx

1 answer

function teleport()
    local char = game:GetService('Players').LocalPlayer.Character
    
    if (char.HumanoidRootPart.Position - part.Position).magnitude <= 20 then
        char.HumanoidRootPart.CFrame = CFrame.new(-185.8, 357.3, -569.6)
    end
end

Remember to define your part at my line 4. And change the 20 to whatever distance you want.

This discussion is preserved as it was. New answers, comments, and votes are closed.