Class · inherits PVInstance
Model
Models are container objects, meaning they group objects together. They are
best used to hold collections of BaseParts and have a number
of functions that extend their functionality.
About Model
Models are container objects, meaning they group objects together. They are
best used to hold collections of BaseParts and have a number
of functions that extend their functionality.
Models are intended to represent geometric groupings. If your grouping has
no geometric interpretation, for instance a collection of
Scripts, use a Folder instead.
Models whose constituent parts are joined together with joints (so that they
can move around or be destroyed via physics simulation) usually have a
PrimaryPart set, as it specifies which part within
the model the pivot and bounding box will "follow" as the model moves. Static
models which stay in one place do not benefit from having a primary part set.
Models have a wide range of applications, including Roblox player characters. They also have a number of unique behaviors that are important to keep in mind:
- When a
Humanoidand aPartnamed Head are parented under a model, a name/health GUI will appear over the model; see Character Name/Health Display for details. - If a part's position on the Y axis hits the
Workspace.FallenPartsDestroyHeightvalue, and it was the last object inside of aModel, the model will be destroyed as well. - When used in a place with
Workspace.StreamingEnabledset to true, the value ofModelStreamingModecontrols various behaviors around how the model and any descendants are replicated and/or removed from clients. In addition, the value ofLevelOfDetailimpacts rendering of the model.
As with all Instance types, the fact that a parent Model is
replicated to a client does not guarantee that all its children are
replicated. This is particularly important if these instances are being
accessed by code running on the client, such as in a LocalScript.
Using ModelStreamingMode with values such as
Atomic can ensure that the entire model and all of
its descendants are present if the parent model exists on the client, or you
can use WaitForChild() when atomicity is not
desired.
Properties 5
LevelOfDetail
: ModelLevelOfDetailSets the level of detail on the model for experiences with instance streaming enabled.Sets the level of detail on the model for experiences with instance streaming enabled. Composite or imposter meshes do not support physics, collision detection, or raycasting.
When set to
StreamingMesh, a lower resolution "imposter" mesh (colored, coarse mesh that wraps around all child parts of the model) renders outside the streaming radius. Does not support textures.When set to
SLIM, a SLIM model (Scalable Lightweight Interactive Model) renders a composite of all child parts at progressively lower resolutions at distances based on the streaming radius. This greatly improves visual quality overStreamingMesh.When set to
DisabledorAutomatic, lower resolution meshes will not be displayed.ModelStreamingMode
: ModelStreamingModeControls the model streaming behavior onModelswhen instance streaming is enabled.Controls how
Modelsare streamed in and out when instance streaming is enabled. Behavior depends on the selected enum. Has no effect when streaming is not enabled.This property should only be changed in Studio via the Properties window when streaming is enabled, or in
Scripts, but never inLocalScripts(doing so can result in undefined behavior).PrimaryPart
: BasePartThe primary part of theModel, ornilif not explicitly set.Points to the primary part of the
Model. The primary part is theBasePartthat acts as the physical reference for the pivot of the model. That is, when parts within the model are moved due to physical simulation or other means, the pivot will move in sync with the primary part.Note that
Modelsdo not havePrimaryPartset by default. If you are creating a model that needs to be acted upon by physics, you should manually set this property in Studio or within a script. If the primary part is not set, the pivot will remain at the same location in world space, even if parts within the model are moved.Also note that when setting this property, it must be a
BasePartthat is a descendant of the model. If you try to setModel.PrimaryPartto aBasePartthat is not a descendant of the model, it will be set to that part but reset tonilduring the next simulation step — this is legacy behavior to support scripts which assume they can temporarily set the primary part to aBasePartwhich isn't a descendant of the model.The general rule for models is that:
- Models whose parts are joined together via physical joints such as
WeldConstraintsorMotor6Dsshould have a primary part assigned. For example, Roblox character models have theirModel.PrimaryPartset to the HumanoidRootPart by default. - Static (usually
Anchored) models which stay in one place unless a script explicitly moves them don't require aModel.PrimaryPartand tend not to benefit from having one set.
- Models whose parts are joined together via physical joints such as
Scale
: floatNotReplicatedNotScriptableEditor-only property used to scale the model around its pivot. Setting this property will move the scale as thoughModel.ScaleTowas called on it.Setting this property in the Properties window will scale the model as though
Model.ScaleTowas called on it, scaling all descendant Instances in the model, such as materials, images, and the 3D geometry of parts, so that the model has the specified scale factor relative to its original size.This property is only available in Studio and will throw an error if used in a
ScriptorLocalScript.Model.ScaleToandModel.GetScaleshould be used from scripts.WorldPivot
: CFrameNotReplicatedDetermines where the pivot of aModelwhich does not have a setModel.PrimaryPartis located.This property determines where the pivot of a
Modelwhich does not have a setModel.PrimaryPartis located. If theModeldoes have aPrimaryPart, the pivot of theModelis equal to the pivot of that primary part instead, and thisWorldPivotproperty is ignored.For a newly created
Model, its pivot will be treated as the center of the bounding box of its contents until the first time itsModel.WorldPivotproperty is set. Once the world pivot is set for the first time, it is impossible to restore this initial behavior.Most commonly, moving the model with the Studio tools, or with model movement functions such as
PVInstance.PivotToandModel.MoveTo, will set the world pivot and thus end this new model behavior.The purpose of this behavior is to allow Luau code to get a sensible pivot simply by creating a new model and parenting objects to it, avoiding the need to explicitly set
Model.WorldPivotevery time you create a model in code.
Methods 9
AddPersistentPlayer
(playerInstance: Player = nil) → ()Sets this model to be persistent for the specified player.ModelStreamingModemust be set toPersistentPerPlayerfor behavior to be changed as a result of addition.Sets this model to be persistent for the specified player. Persistent models stay present for the player regardless of streaming settings or conditions.
ModelStreamingModemust be set toPersistentPerPlayerfor behavior to be changed as a result of addition.GetBoundingBox
() → TupleReturns a description of a volume that contains all parts of a Model.This function returns a description of a volume that contains all
BasePartchildren within aModel. The volume's orientation is based on the orientation of thePrimaryPart, and matches the selection box rendered in Studio when the model is selected. Mirroring the behavior ofTerrain.FillBlock, it returns aCFramerepresenting the center of that bounding box and aVector3representing its size. The size may be inaccurate at runtime if physics constraints are acting upon the parts within theModel.The orientation of the bounding box matches the orientation of the
Pivot- either the pivot of thePrimaryPart(if present) or theWorldPivotof the model.GetExtentsSize
() → Vector3Returns the size of the smallest bounding box that contains all of theBasePartsin theModel, aligned with theModel.PrimaryPartif it is set.Returns the size of the smallest bounding box that contains all of the
BasePartsin theModel. The orientation matches the orientation of thePivot- either the pivot of thePrimaryPart(if present) or theWorldPivotof the model.Note this function only returns the size of the smallest bounding box, and the developer must employ their own method to obtain the position of the bounding box.
GetPersistentPlayers
() → List<Player>Returns all thePlayerobjects that this model object is persistent for. Behavior varies based on whether this method is called from aScriptor aLocalScript.When this method is called from a
Script, it returns all thePlayerobjects that this model is persistent for. When called from aLocalScript, this method only checks if this model is persistent for theLocalPlayer.GetScale
() → floatReturns the canonical scale of the model, which defaults to 1 for newly created models and will change as it is scaled viaModel.ScaleTo.Models contain a persistent canonical scale factor, which starts out at 1 for newly created models and changes as the model is scaled by calling
Model.ScaleTo. This function returns the current canonical scale factor of the model.The current scale factor does not directly impact the size of Instances under the model. It is used for content authoring and scripting purposes to remember how the model has been scaled relative to its original size.
Within a given session, the model will cache the precise original size information of the descendant Instances after the first
Model.ScaleTocall. This means that callingScaleTo(x)followed byScaleTo(1)will get you back exactly the original configuration of the model with no floating point drift. Avoiding floating point drift is the motivation for having a ScaleTo function instead of a ScaleBy function.The scale factor does impact engine behavior in one way: The scale factor of a model will be applied to joint offsets of
Animationsplayed on anAnimationControllerunder that model, so that animated rigs will correctly play back animations even when scaled.MoveTo
(position: Vector3) → ()Moves thePrimaryPartto the given position. If a primary part has not been specified, the root part of the model will be used.Moves the
PrimaryPartto the given position. If a primary part has not been specified, the root part of the model will be used, but the root part is not deterministic and it is recommended that you always set a primary part when usingMoveTo().If there are any obstructions where the model is to be moved, such as
Terrainor otherBaseParts, the model will be moved vertically upward until there is nothing in the way. If this behavior is not desired,PVInstance.PivotToshould be used instead.Note that rotation is not preserved when moving a model with
MoveTo(). It is recommended to use eitherTranslateBy()orPVInstance.PivotToif the current rotation of the model needs to be preserved.RemovePersistentPlayer
(playerInstance: Player = nil) → ()Makes this model no longer persistent for the specified player.ModelStreamingModemust be set toPersistentPerPlayerfor behavior to be changed as a result of removal.Makes this model no longer persistent for the specified player. This does not guarantee the model will immediately be removed for the player; after calling this method, the model will be treated as
Atomicfor that player and will remain present as long as it is within the target streaming radius.ModelStreamingModemust be set toPersistentPerPlayerfor behavior to be changed as a result of removal.ScaleTo
(newScaleFactor: float) → ()Sets the scale factor of the model, adjusting the sizing and location of all descendant Instances such that they have that scale factor relative to their initial sizes and locations when scale factor was 1.Models contain a persistent canonical scale factor, which starts out at 1 for newly created models. This function scales the model, around the pivot location, relative to how it would look at a scale factor of 1. To accomplish this it does two things:
- Sets the current scale factor of the model to the specified value
- Resizes and repositions all descendant Instances accordingly
The scaling of locations is done around the pivot location.
All "geometric" properties of descendant Instances will be scaled. That obviously includes the sizes of parts, but here are some other examples of properties which are scaled:
- The length of joints like
WeldConstraints, andRopeConstraint - Physical velocities and forces like
HingeConstraint - Visual properties like sizes of particle emitters
- Other length properties like
Sound.RollOffMinDistance
TranslateBy
(delta: Vector3) → ()Shifts aModelby the givenVector3offset, preserving the model's orientation. If anotherBasePartorTerrainalready exists at the new position then theModelwill overlap said object.Shifts a
Modelby the givenVector3offset, preserving the model's orientation. If anotherBasePartorTerrainalready exists at the new position then theModelwill overlap said object.The translation is applied in world space rather than object space, meaning even if the model's parts are orientated differently it will still move along the standard axis.
Model also has every member of PVInstance. Deprecated and Roblox-only members are hidden.
Reference text from the Roblox Creator Documentation, licensed CC BY 4.0, reorganized by rbxtoolshub.com · Studio 0.743.0.7431133.