Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by 5 years ago
Edited 5 years ago

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

Log in to vote
0
Answered by 5 years ago
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.

Ad

Answer this question