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

How do I get this part to teleport to the right place?

Asked by
OBenjOne 190
5 years ago
Edited 5 years ago

I have been trying to get this script to work:

Position = workspace.TeleportPlace.Position Script.Parent.Position = Position

It seems like this would be so simple, however this ALWAYS teleports the part to the position Vector3.new(0,0,0) no matter where TeleportPlace is! Really confusing

I have tried just copying the position of TeleportPlace and putting it in the script like so:

Position =Vector3.new(1000,600,-351) -- or some other number Script.Parent.Position = Position

Mysteriously, this works just fine

None of these scripts give an error and the position of TeleportPlace never changes

EDIT: my first goal for this question is to find out a script that works. However my second goal is to find out what was wrong with mine so I can avoid similar mistakes in the future

0
Try using CFrames. Just swap the Positions with CFrame T1mes 230 — 5y

4 answers

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

Hello, here is how I did it.

part = script.Parent --Gets the part that will be teleporting 
tpPart = workspace.TeleportPlace.Position --Gets the part that you want to tp to.
part.CFrame = CFrame.new(tpPart.X, tpPart.Y, tpPart.Z) --Changes the parts CFrame to the tpPart's position

Hope this helps!

0
I will try that OBenjOne 190 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

I don't really know how to explain what I did, I just know how I did it.

Here is the script that works for me.

model = game.Workspace.Part -- switch this to the part you're teleporting
location = game.Workspace.PositionPart -- this the part you want to tp to

model.CFrame = CFrame.new(location.X, location.Y, location.Z)

Alternatively you could try swapping out the CFrame.new section with coordinates if you didn't want to tp to a part, although I haven't tested that.

Log in to vote
0
Answered by 5 years ago

Its because you are doing Position = workspace.TeleportPlace.Position and then doing Script.Parent.Position = Position all in the same line.. This will error. Instead do it like this!

local Position = workspace.TeleportPlace.Position -- Get the position
Script.Parent.Position = Position -- Set the position

How-ever using position will put the part right above the part you are teleportating it to. If you want the part to go into the part you are teleporting to.. Use CFrame like this

local cframe = workspace.TeleportPlace.CFrame -- Get the position and rotation
Script.Parent.CFrame = cframe -- Set the position and rotation

Another advantage of cframe is that it includes rotation un-like just setting the position.

0
If this helped or worked, please click the correct answer! Thanks! Have a nice day! c: outlook1234567890 115 — 5y
Log in to vote
0
Answered by
SCP774 191
5 years ago
Position = workspace.TeleportPlace.Position Script.Parent.Position = Position

First, you should ALWAYS use Vector3 or CFrame for part teleportations. (Only use CFrame for character teleportations, since Vector3 will kill the character.) Second, you should not use Position as a variable, as it will overwrite the Position property.

Pos = Vector3.new(workspace.TeleportPlace.Position)
Script.Parent.Position = Pos

Hope that helped!

Answer this question