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
| Name | Parameters | Returns | Description |
|---|---|---|---|
| GetPivot():CFrame | Void | CFrame | Returns the object's current pivot - the BasePart's own CFrame, or a Model's designated pivot CFrame. |
| PivotTo(targetCFrame: CFrame):void | targetCFrame: CFrame | void | Moves 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,Vector3 | Void | CFrame, Vector3 | Returns a CFrame and a Size describing the smallest axis-aligned box that contains every BasePart within the object. |
Inherited from Instance
| Name | Parameters | Returns | Description |
|---|---|---|---|
| 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: string | Instance? | 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: string | Instance? | Returns the first ancestor of the Instance whose Name equals the given name, or nil if none exists. |
| FindFirstAncestorOfClass(className: string):Instance? | className: string | Instance? | 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):boolean | ancestor: Instance | boolean | Returns true if the Instance is a descendant of the given ancestor. |
| IsAncestorOf(descendant: Instance):boolean | descendant: Instance | boolean | Returns true if the Instance is an ancestor of the given descendant. |
| GetFullName():string | Void | string | Returns a string describing the Instance's ancestry, formed by concatenating Names with periods. |
| Clone():Instance? | Void | Instance? | 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():void | Void | void | Sets Parent to nil, locks the Parent property, disconnects all connections, and calls Destroy() on all children. |
| IsA(className: string):boolean | className: string | boolean | Returns true if the Instance's class matches or inherits from the given class. |
| SetAttribute(attribute: string,value: Variant):void | attribute: string, value: Variant | void | Sets the attribute with the given name to the given value. |
| GetAttribute(attribute: string):Variant | attribute: string | Variant | Returns 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):RBXScriptSignal | attribute: string | RBXScriptSignal | Returns an event that fires whenever the given attribute's value changes. |
| GetPropertyChangedSignal(property: string):RBXScriptSignal | property: string | RBXScriptSignal | Returns 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. |
Related
- BasePart - the physical, single-part side of this hierarchy.
- Model - the grouping side of this hierarchy.
Constructors
Inherited from Instance
| Name | Description |
|---|---|
| new(className: string,parent: Instance?):Instance | Creates 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
| Name | Type | Description |
|---|---|---|
| ClassName | string | Read-only string naming the class this Instance belongs to. |
| Name | string | A non-unique identifier of the Instance, used for organization and for accessing it in code. Maximum of 100 characters. |
| Parent | Instance | The hierarchical parent of the Instance. Setting this to nil removes the Instance from the DataModel tree unless something else still references it. |
| Archivable | boolean | Whether the Instance is included when the experience is published or saved, or when Clone() is called. |
| UniqueId | UniqueId | A read-only identifier for the Instance, distinct from Name, which is not guaranteed to be unique. |
Events
Inherited from Instance
| Name | Parameters | Description |
|---|---|---|
| Changed(property: string) | property: string | Fires whenever any property of the Instance changes, passing the name of the property that changed. |
| ChildAdded(child: Instance) | child: Instance | Fires when a new child is directly parented to the Instance. |
| ChildRemoved(child: Instance) | child: Instance | Fires when a direct child is removed (its Parent set to something else or nil). |
| DescendantAdded(descendant: Instance) | descendant: Instance | Fires when any descendant (a child, or a child's child, and so on) is added anywhere below the Instance. |
| DescendantRemoving(descendant: Instance) | descendant: Instance | Fires right before any descendant is about to be removed from the hierarchy below the Instance. |
| AncestryChanged(child: Instance,parent: Instance) | child: Instance, parent: Instance | Fires when the Parent property of the Instance, or any of its ancestors, changes. |
| AttributeChanged(attribute: string) | attribute: string | Fires whenever any attribute on the Instance changes, passing the attribute's name. |
| Destroying() | Void | Fires immediately before the Instance is destroyed by Destroy(), while it (and its descendants) can still be read one last time. |