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

how do you teleport a player ??

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

✓ Accepted answer

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)

2 comments

0

thanks

0

You really should use rootpart or :SetPrimaryPartCFrame if you allow R15.

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)

1 comment

0

thanks

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

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