PVInstance along with all of its descendant
PVInstance|PVInstances such that the pivot is now located at the specified
datatype/CFrame. This is the primary function that should be used to move
Model|Models via scripting.
BasePart|BaseParts are moved in this way by having their
datatype/CFrame transformed by the necessary offset.
Model|Models are moved in this way by having their
Model/WorldPivot transformed by the necessary offset.
Note that for efficiency purposes,
Instance/Changed events are not fired for
BasePart|BaseParts moved in this way; they are only fired for
Model|Models, the offsets of the descendant parts and models are cached, such that subsequent calls to
PVInstance/PivotTo|PivotTo on the same model do not accumulate floating point drift between the parts making up the model.
BasePart|BaseParts are both
PVInstance|PVInstances (“Position Velocity Instances”) and so both have this function.
Simple Character Teleportation
This code sample is a simple teleport script that moves your character 10 studs forwards in the direction you’re currently facing when you press the F key. It does so by getting the current pivot with
PVInstance/GetPivot and calling
PVInstance|PivotTo to move the character forwards.
-- This code should be placed in a LocalScript under StarterPlayerScripts local Players = game:GetService("Players") local ContextActionService = game:GetService("ContextActionService") local function doTeleport() local player = Players.LocalPlayer local character = player.Character if character and character.Parent then -- Move the character 10 studs forwards in the direction they're facing local currentPivot = character:GetPivot() character:PivotTo(currentPivot * CFrame.new(0, 0, -10)) end end ContextActionService:BindAction("Teleport", doTeleport, true, Enum.KeyCode.F)