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

How do i make a script which teleports a player?

Asked by 7 years ago

Before you read this; i have very limited knowledge of lua.

This is a script i got off the wiki.

game.Workspace.Player.Torso.Position = Vector3.new(tonumber(x),tonumber(y),tonumber(z))

"x", "y" and "z" are meant to be chosen by the player.

I need to:

A) make a GUI

B) allow the player to input x, y and z values into the GUI

I don't know if the script actually works. I tested it and apparently, it was wrong. If it IS correct, then tell me.

3 answers

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

You're right, that code won't quite work. It'll teleport for the torso, but not the rest of the body, resulting in death.

To properly do this, I would suggest using char:MoveTo(Vector3.new(tonumber(x),tonumber(y),tonumber(z)))

Another thing I noticed however, is that this code would only work if the person's name was "Player." To fix this, I would consider getting the player from local plr = game.Players.LocalPlayer since this involves a LocalScript, and then get the character from local char = plr.Character or plr.CharacterAdded:wait() and using the MoveTo() on char

Ad
Log in to vote
0
Answered by 7 years ago

That approach off the wiki is slightly outdated but a similar approach can still work as an alternative to MadWorlds solution of using MoveTo(), you can also just CFrame the torso.

local x,y,z = 0,0,0
game.Workspace.Player.Torso.CFrame = CFrame.new(tonumber(x),tonumber(y),tonumber(z))
Log in to vote
0
Answered by 7 years ago

A quick and efficient way, is to do this

Create a part in workspace disable collision, anchor it, change the transparency to 0 and lastly, move it to where you want to be teleported.

I'm also assuming the script is a local script.

local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:wait()
local tp = workspace.TPBrick -- change "TPBrick" to the part you made.

char.HumanoidRootPart.Position = Vector3.new(tp.Position) -- code that teleports you.

Answer this question