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

how do you teleport a player ??

Asked by 7 years ago

so ive allready read and tried this http://wiki.roblox.com/index.php?title=Teleportation it dind't work ..

but what i try to do is if you press X u get teleported so

if script.Parent.TP.Enabled == true then
    function Pressx(key)
       if(key == "x") then
          --game.Workspace.Player.HumanoidRootPart.CFrame = CFrame.new(Vector3.new(-2.7, -151.9, -580.5))  dind't  work

       end
    end
end

3 answers

Log in to vote
0
Answered by
cabbler 1942 Moderation Voter
7 years ago

You tried to index "game.Workspace.Player" but likely "Player" is not a player in your game. Look at the output.

The simplest way to teleport is by cframing the torso. If you want to do it on 'X' then here is how.

game:GetService('UserInputService').InputBegan:connect(function(input,gpe)
    if (not gpe) and input.KeyCode == Enum.KeyCode.X then
        game.Players.LocalPlayer.Character.Torso.CFrame = CFrame.new(Vector3.new(-2.7, -151.9, -580.5))
    end
end)
0
thanks TigerClaws454 48 — 7y
0
You really should use rootpart or :SetPrimaryPartCFrame if you allow R15. cabbler 1942 — 7y
Ad
Log in to vote
0
Answered by 7 years ago

Like cabbler said, the problem likely is you tried to index 'Player' as though it were an actual Model/Character inside the workspace. To add upon what he said, it's better to use HumanoidRootPart to ensure compatibility with R15. Here's an updated version of your code:

game:GetService("UserInputService").InputBegan:connect(function(input, guiStatus)
    if not guiStatus and input.KeyCode == Enum.KeyCode.X then
        game:GetService("Players").LocalPlayer.Character.HumanoidRootPart.CFrame = CFrame.new(Vector3.new(-2.7, -151.9, -580.5))
    end
end)

0
thanks TigerClaws454 48 — 7y
Log in to vote
0
Answered by 7 years ago
if script.Parent.TP.Enabled == true then
    function Pressx(key)
       if(key == "x") then

        game.Players.LocalPlayer.Character.Torso.CFrame = Vector3.new(0, 0, 0)

       end
    end
end

Answer this question