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
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!
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.
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.
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!