PVInstance

Inherits from: Instance

An abstract base class - it's never created directly (there's no real object that's "just" a PVInstance), but both BasePart and Model inherit from it. It exists purely to give both of those a shared, uniform way to read and move their position/orientation in the world, called their pivot - a BasePart's pivot is just its own CFrame, while a Model's pivot is a single CFrame representing the whole group, independent of how its parts are arranged inside it.

Code Snippet

local function moveToSpawn(pvInstance, spawnCFrame)
	-- Works identically whether pvInstance is a single Part or an entire Model -
	-- that's the whole point of PVInstance being the shared ancestor.
	pvInstance:PivotTo(spawnCFrame)
end

local part = workspace:FindFirstChild("Rock")
local model = workspace:FindFirstChild("Castle")

moveToSpawn(part, CFrame.new(0, 5, 0))
moveToSpawn(model, CFrame.new(50, 5, 0))

local currentPivot = model:GetPivot()
print(currentPivot.Position)

Methods

NameParametersReturnsDescription
GetPivot():CFrameVoidCFrameReturns the object's current pivot - the BasePart's own CFrame, or a Model's designated pivot CFrame.
PivotTo(targetCFrame: CFrame):voidtargetCFrame: CFramevoidMoves the object so its pivot matches targetCFrame. On a Model, every part inside moves together, preserving their relative arrangement - this is the modern, correct way to reposition a Model (prefer it over setting PrimaryPart's CFrame).
GetBoundingBox():CFrame,Vector3VoidCFrame, Vector3Returns a CFrame and a Size describing the smallest axis-aligned box that contains every BasePart within the object.

Inherited from Instance

NameParametersReturnsDescription
FindFirstChild(name: string,recursive: boolean?):Instance?name: string, recursive: boolean?Instance?Returns the first child of the Instance with the given name, or nil if no such child exists. Searches descendants too if recursive is true.
FindFirstChildOfClass(className: string):Instance?className: stringInstance?Returns the first child of the Instance whose ClassName equals the given className, or nil if none exists.
FindFirstChildWhichIsA(className: string,recursive: boolean?):Instance?className: string, recursive: boolean?Instance?Returns the first child whose class matches or inherits from className (unlike FindFirstChildOfClass, which requires an exact match), or nil if none exists.
FindFirstAncestor(name: string):Instance?name: stringInstance?Returns the first ancestor of the Instance whose Name equals the given name, or nil if none exists.
FindFirstAncestorOfClass(className: string):Instance?className: stringInstance?Returns the first ancestor of the Instance whose ClassName equals the given className, or nil if none exists.
WaitForChild(childName: string,timeOut: number?):Instance?childName: string, timeOut: number?Instance?Yields the current thread until a child with the given name exists, then returns it. If timeOut is given and exceeded, returns nil instead of continuing to wait.
GetChildren():{Instance}Void{Instance}Returns an array containing all of the Instance's direct children.
GetDescendants():{Instance}Void{Instance}Returns an array containing all of the Instance's descendants.
IsDescendantOf(ancestor: Instance):booleanancestor: InstancebooleanReturns true if the Instance is a descendant of the given ancestor.
IsAncestorOf(descendant: Instance):booleandescendant: InstancebooleanReturns true if the Instance is an ancestor of the given descendant.
GetFullName():stringVoidstringReturns a string describing the Instance's ancestry, formed by concatenating Names with periods.
Clone():Instance?VoidInstance?Creates a copy of the Instance and all of its descendants, ignoring any that are not Archivable. Returns nil if the Instance itself is not Archivable.
Destroy():voidVoidvoidSets Parent to nil, locks the Parent property, disconnects all connections, and calls Destroy() on all children.
IsA(className: string):booleanclassName: stringbooleanReturns true if the Instance's class matches or inherits from the given class.
SetAttribute(attribute: string,value: Variant):voidattribute: string, value: VariantvoidSets the attribute with the given name to the given value.
GetAttribute(attribute: string):Variantattribute: stringVariantReturns the value assigned to the given attribute name, or nil if not set.
GetAttributes():{[string]: Variant}Void{[string]: Variant}Returns a dictionary of every attribute set on the Instance, keyed by attribute name.
GetAttributeChangedSignal(attribute: string):RBXScriptSignalattribute: stringRBXScriptSignalReturns an event that fires whenever the given attribute's value changes.
GetPropertyChangedSignal(property: string):RBXScriptSignalproperty: stringRBXScriptSignalReturns an event that fires whenever the given property changes, useful for properties (like Position on a BasePart) that don't have their own dedicated event.

Constructors

Inherited from Instance

NameDescription
new(className: string,parent: Instance?):InstanceCreates a new Instance of the given class name. Abstract classes and services cannot be created with this constructor. Setting parent in the constructor is discouraged for performance reasons - prefer setting the Parent property last, after all other properties are set.

Properties

Inherited from Instance

NameTypeDescription
ClassNamestringRead-only string naming the class this Instance belongs to.
NamestringA non-unique identifier of the Instance, used for organization and for accessing it in code. Maximum of 100 characters.
ParentInstanceThe hierarchical parent of the Instance. Setting this to nil removes the Instance from the DataModel tree unless something else still references it.
ArchivablebooleanWhether the Instance is included when the experience is published or saved, or when Clone() is called.
UniqueIdUniqueIdA read-only identifier for the Instance, distinct from Name, which is not guaranteed to be unique.

Events

Inherited from Instance

NameParametersDescription
Changed(property: string)property: stringFires whenever any property of the Instance changes, passing the name of the property that changed.
ChildAdded(child: Instance)child: InstanceFires when a new child is directly parented to the Instance.
ChildRemoved(child: Instance)child: InstanceFires when a direct child is removed (its Parent set to something else or nil).
DescendantAdded(descendant: Instance)descendant: InstanceFires when any descendant (a child, or a child's child, and so on) is added anywhere below the Instance.
DescendantRemoving(descendant: Instance)descendant: InstanceFires right before any descendant is about to be removed from the hierarchy below the Instance.
AncestryChanged(child: Instance,parent: Instance)child: Instance, parent: InstanceFires when the Parent property of the Instance, or any of its ancestors, changes.
AttributeChanged(attribute: string)attribute: stringFires whenever any attribute on the Instance changes, passing the attribute's name.
Destroying()VoidFires immediately before the Instance is destroyed by Destroy(), while it (and its descendants) can still be read one last time.