| Platform: Not CreatableThe Platform object creates a brick that when touched by a Player will |
| anchor their torso to the brick. This allows for the creation of vehicles that |
| players can stand in and not be flung about the cabin/deck of the vehicle. |
| The Platform is almost identical to the Seat object, except that |
| instead of sitting down the player will be standing while locked in place. |
| Good for ships. |
| The Platform object is very useful for making people's characters staying in |
| one spot while they move around, such as a ship or truck. When a player |
| touches the Platform a Weld constraint is created, so they are |
| 'attached' to the Platform and can't move until that weld is broken. It can be |
| removed by hitting the spacebar, when the player jumps to exit the Platform.SummaryPropertiesProperties inherited from PartShape: PartTypeSets the overall shape of the object.NOT REPLICATEDProperties inherited from FormFactorPartFormFactor: FormFactorNOT REPLICATEDDEPRECATEDformFactor: FormFactorHIDDENNOT REPLICATEDDEPRECATEDProperties inherited from BasePartAnchored: booleanDetermines whether a part is immovable by physics.AssemblyAngularVelocity: Vector3The angular velocity of the part's assembly.NOT REPLICATEDAssemblyCenterOfMass: Vector3The center of mass of the part's assembly in world space.READ ONLYNOT REPLICATEDAssemblyLinearVelocity: Vector3The linear velocity of the part's assembly.NOT REPLICATEDAssemblyMass: numberThe total mass of the part's assembly.READ ONLYNOT REPLICATEDAssemblyRootPart: BasePartA reference to the root part of the assembly.READ ONLYNOT REPLICATEDBackParamA: numberDetermines the first parameter for the SurfaceType on the Back face of a |
| part (+Z direction).HIDDENDEPRECATEDBackParamB: numberDetermines the second parameter for the SurfaceType on the Back face of a |
| part (+Z direction).HIDDENDEPRECATEDBackSurface: SurfaceTypeDetermines the type of surface for the Back face of a part (+Z direction).BackSurfaceInput: InputTypeDetermines the kind of input for the Back face of a part (+Z direction).HIDDENDEPRECATEDBottomParamA: numberDetermines the first parameter for the SurfaceType on the Bottom face of a |
| part (-Y direction).HIDDENDEPRECATEDBottomParamB: numberDetermines the second parameter for the SurfaceType on the Bottom face of |
| a part (-Y direction).HIDDENDEPRECATEDBottomSurface: SurfaceTypeDetermines the type of surface for the Bottom face of a part (-Y |
| direction).BottomSurfaceInput: InputTypeDetermines the kind of input for the Bottom face of a part (-Y direction).HIDDENDEPRECATEDBrickColor: BrickColorDetermines the color of a part.NOT REPLICATEDCFrame: CFrameDetermines the position and orientation of the BasePart in the |
| world.CanCollide: booleanDetermines whether a part may collide with other parts.CanQuery: booleanDetermines whether the part is considered during spatial query operations.CanTouch: booleanDetermines if Touched and |
| TouchEnded events fire on the part.CastShadow: booleanDetermines whether or not a part casts a shadow.CenterOfMass: Vector3Describes the world position in which a part's center of mass is located.READ ONLYNOT REPLICATEDCollisionGroup: stringDescribes the name of a part's collision group.NOT REPLICATEDCollisionGroupId: numberDescribes the automatically set ID number of a part's collision group.NOT REPLICATEDDEPRECATEDColor: Color3Determines the color of a part.NOT REPLICATEDCurrentPhysicalProperties: PhysicalPropertiesIndicates the current physical properties of the part.READ ONLYNOT REPLICATEDCustomPhysicalProperties: PhysicalPropertiesDetermines several physical properties of a part.Elasticity: numberUsed to control the Elasticity of the part, but it no longer does |
| anything.HIDDENNOT REPLICATEDDEPRECATEDEnableFluidForces: booleanUsed to enable or disable aerodynamic forces on parts and assemblies.ExtentsCFrame: CFrameThe CFrame of the physical extents of the BasePart.READ ONLYNOT REPLICATEDExtentsSize: Vector3The actual physical size of the BasePart as regarded by the |
| physics engine.READ ONLYNOT REPLICATEDFriction: numberUsed to control the Friction of the part, but now it no longer does |
| anything.HIDDENNOT REPLICATEDDEPRECATEDFrontParamA: numberDetermines the first parameter for the SurfaceType on the Front face of a |
| part (-Z direction).HIDDENDEPRECATEDFrontParamB: numberDetermines the second parameter for the SurfaceType on the Front face of a |
| part (-Z direction).HIDDENDEPRECATEDFrontSurface: SurfaceTypeDetermines the type of surface for the Front face of a part (-Z |
| direction).FrontSurfaceInput: InputTypeDetermines the kind of input for the Front face of a part (-Z direction).HIDDENDEPRECATEDLeftParamA: numberDetermines the first parameter for the SurfaceType on the Left face of a |
| part (-Z direction).HIDDENDEPRECATEDLeftParamB: numberDetermines the second parameter for the SurfaceType on the Left face of a |
| part (-Z direction).HIDDENDEPRECATEDLeftSurface: SurfaceTypeDetermines the type of surface for the Left face of a part (-X direction).LeftSurfaceInput: InputTypeDetermines the kind of input for the Left face of a part (+X direction).HIDDENDEPRECATEDLocalTransparencyModifier: numberDetermines a multiplier for BasePart.Transparency that is only |
| visible to the local client.HIDDENNOT REPLICATEDLocked: booleanDetermines whether a part is selectable in Studio.Mass: numberDescribes the mass of the part, the product of its density and volume.READ ONLYNOT REPLICATEDMassless: booleanDetermines whether the part contributes to the total mass or inertia of |
| its rigid body.Material: MaterialDetermines the texture and default physical properties of a part.MaterialVariant: stringThe name of MaterialVariant.NOT REPLICATEDOrientation: Vector3Describes the rotation of the part in the world.HIDDENNOT REPLICATEDPivotOffset: CFrameSpecifies the offset of the part's pivot from its CFrame.Position: Vector3Describes the position of the part in the world.HIDDENNOT REPLICATEDReceiveAge: numberTime since last recorded physics update.HIDDENREAD ONLYNOT REPLICATEDReflectance: numberDetermines how much a part reflects the skybox.ResizeIncrement: numberDescribes the smallest change in size allowable by the Resize method.READ ONLYNOT REPLICATEDResizeableFaces: FacesDescribes the faces on which a part may be resized.READ ONLYNOT REPLICATEDRightParamA: numberDetermines the first parameter for the SurfaceType on the Right face of a |
| part (-X direction).HIDDENDEPRECATEDRightParamB: numberDetermines the second parameter for the SurfaceType on the Right face of a |
| part (-X direction).HIDDENDEPRECATEDRightSurface: SurfaceTypeDetermines the type of surface for the Right face of a part (+X |
| direction).RightSurfaceInput: InputTypeDetermines the kind of input for the Right face of a part (-X direction).HIDDENDEPRECATEDRootPriority: numberThe main rule in determining the root part of an assembly.RotVelocity: Vector3Determines a part's change in orientation over time.HIDDENDEPRECATEDRotation: Vector3The rotation of the part in degrees for the three axes.NOT REPLICATEDSize: Vector3Determines the dimensions of a part (length, width, height).NOT REPLICATEDSpecificGravity: numberThe ratio of the part's density to the density of water determined by the |
| BasePart.Material.READ ONLYNOT REPLICATEDDEPRECATEDTopParamA: numberDetermines the first parameter for the SurfaceType on the Top face of a |
| part (+Y direction).HIDDENDEPRECATEDTopParamB: numberDetermines the second parameter for the SurfaceType on the Top face of a |
| part (+Y direction).HIDDENDEPRECATEDTopSurface: SurfaceTypeDetermines the type of surface for the Top face of a part (+Y direction).TopSurfaceInput: InputTypeDetermines the kind of input for the Top face of a part (+Y direction).HIDDENDEPRECATEDTransparency: numberDetermines how much a part can be seen through (the inverse of part |
| opacity).Velocity: Vector3Determines a part's change in position over time.HIDDENDEPRECATEDbrickColor: BrickColorNOT REPLICATEDDEPRECATEDProperties inherited from PVInstanceOrigin: CFrameNOT REPLICATEDNOT SCRIPTABLEPivot Offset: CFrameNOT REPLICATEDNOT SCRIPTABLEProperties inherited from InstanceArchivable: booleanDetermines if an Instance can be cloned using |
| Instance:Clone() or saved to file.ClassName: stringA read-only string representing the class this Instance belongs |
| to.READ ONLYNOT REPLICATEDName: stringA non-unique identifier of the Instance.Parent: InstanceDetermines the hierarchical parent of the Instance.NOT REPLICATEDRobloxLocked: booleanA deprecated property that used to protect CoreGui objects.HIDDENarchivable: booleanHIDDENNOT REPLICATEDDEPRECATEDclassName: stringREAD ONLYNOT REPLICATEDDEPRECATEDMethodsMethods inherited from BasePartApplyAngularImpulse(impulse: Vector3): void Apply an angular impulse to the assembly.ApplyImpulse(impulse: Vector3): void Apply an impulse to the assembly at the assembly's |
| center of mass.ApplyImpulseAtPosition(impulse: Vector3, position: Vector3): void Apply an impulse to the assembly at specified position.BreakJoints(): void DEPRECATEDBreaks any surface connection with any adjacent part, including |
| Weld and other JointInstance.CanCollideWith(part: BasePart): boolean Returns whether the parts can collide with each other.CanSetNetworkOwnership(): Tuple Checks whether you can set a part's network ownership.GetClosestPointOnSurface(position: Vector3): Vector3 GetConnectedParts(recursive: boolean): Objects Returns a table of parts connected to the object by any kind of rigid |
| joint.GetJoints(): Objects Return all Joints or Constraints that is connected to this Part.GetMass(): number Returns the value of the Mass property.GetNetworkOwner(): Instance Returns the current player who is the network owner of this part, or nil |
| in case of the server.GetNetworkOwnershipAuto(): boolean Returns true if the game engine automatically decides the network owner |
| for this part.GetNoCollisionConstraints(): Objects GetRenderCFrame(): CFrame DEPRECATEDOBSOLETE. Returns a CFrame describing where the part is being rendered at.GetRootPart(): Instance Returns the base part of an assembly of parts.GetTouchingParts(): Objects Returns a table of all BasePart.CanCollide true parts that |
| intersect with this part.GetVelocityAtPosition(position: Vector3): Vector3 Returns the linear velocity of the part's assembly at the given position |
| relative to this part.IsGrounded(): boolean Returns true if the object is connected to a part that will hold it in |
| place (eg an BasePart.Anchored part), otherwise returns false.MakeJoints(): void DEPRECATEDCreates a joint on any side of the object that has a surface ID that can |
| make a joint.Resize(normalId: NormalId, deltaAmount: number): boolean Changes the size of an object just like using the Studio resize tool.SetNetworkOwner(playerInstance: Player): void Sets the given player as network owner for this and all connected parts.SetNetworkOwnershipAuto(): void Lets the game engine dynamically decide who will handle the part's physics |
| (one of the clients or the server).breakJoints(): void DEPRECATEDgetMass(): number DEPRECATEDmakeJoints(): void DEPRECATEDresize(normalId: NormalId, deltaAmount: number): boolean DEPRECATEDIntersectAsync(parts: Objects, collisionfidelity: CollisionFidelity, renderFidelity: RenderFidelity): Instance YIELDSCreates a new IntersectOperation from the overlapping geometry of |
| the part and the other parts in the given array.SubtractAsync(parts: Objects, collisionfidelity: CollisionFidelity, renderFidelity: RenderFidelity): Instance YIELDSCreates a new UnionOperation from the part, minus the geometry |
| occupied by the parts in the given array.UnionAsync(parts: Objects, collisionfidelity: CollisionFidelity, renderFidelity: RenderFidelity): Instance YIELDSCreates a new UnionOperation from the part, plus the geometry |
| occupied by the parts in the given array.Methods inherited from PVInstanceGetPivot(): CFrame Gets the pivot of a PVInstance.PivotTo(targetCFrame: CFrame): void Transforms the PVInstance along with all of its descendant |
| PVInstances such that the pivot is now located at the |
| specified CFrame.Methods inherited from InstanceAddTag(tag: string): void Applies a tag to the instance.ClearAllChildren(): void This function destroys all of an Instance's children.Clone(): Instance Create a copy of an object and all its descendants, ignoring objects that |
| are not Archivable.Destroy(): void Sets the Instance.Parent property to nil, locks the |
| Instance.Parent property, disconnects all connections, and calls |
| Destroy on all children.FindFirstAncestor(name: string): Instance Returns the first ancestor of the Instance whose |
| Instance.Name is equal to the given name.FindFirstAncestorOfClass(className: string): Instance Returns the first ancestor of the Instance whose |
| Instance.ClassName is equal to the given className.FindFirstAncestorWhichIsA(className: string): Instance Returns the first ancestor of the Instance for whom |
| Instance:IsA() returns true for the given className.FindFirstChild(name: string, recursive: boolean): Instance Returns the first child of the Instance found with the given name.FindFirstChildOfClass(className: string): Instance Returns the first child of the Instance whose |
| ClassName is equal to the given className.FindFirstChildWhichIsA(className: string, recursive: boolean): Instance Returns the first child of the Instance for whom |
| Instance:IsA() returns true for the given className.FindFirstDescendant(name: string): Instance Returns the first descendant found with the given Instance.Name.GetActor(): Actor Returns the Actor associated with the Instance, if any.GetAttribute(attribute: string): Variant Returns the attribute which has been assigned to the given name.GetAttributeChangedSignal(attribute: string): RBXScriptSignal Returns an event that fires when the given attribute changes.GetAttributes(): table Returns a dictionary of string → variant pairs for each of the |
| Instance's attributes.GetChildren(): Objects Returns an array containing all of the Instance's children.GetDebugId(scopeLength: number): string NOT BROWSABLEReturns a coded string of the Instances DebugId used internally by |
| Roblox.GetDescendants(): Array CUSTOM LUA STATEReturns an array containing all of the descendants of the instance.GetFullName(): string Returns a string describing the Instance's ancestry.GetPropertyChangedSignal(property: string): RBXScriptSignal Get an event that fires when a given property of an object changes.GetTags(): Array Gets an array of all tags applied to the instance.HasTag(tag: string): boolean Check whether the instance has a given tag.IsA(className: string): boolean CUSTOM LUA STATEReturns true if an Instance's class matches or inherits from a |
| given class.IsAncestorOf(descendant: Instance): boolean Returns true if an Instance is an ancestor of the given |
| descendant.IsDescendantOf(ancestor: Instance): boolean Returns true if an Instance is a descendant of the given ancestor.Remove(): void DEPRECATEDSets the object's Parent to nil, and does the same for all its |
| descendants.RemoveTag(tag: string): void Removes a tag from the instance.SetAttribute(attribute: string, value: Variant): void Sets the attribute with the given name to the given value.WaitForChild(childName: string, timeOut: number): Instance CUSTOM LUA STATE, CAN YIELDReturns the child of the Instance with the given name. If the |
| child does not exist, it will yield the current thread until it does.children(): Objects DEPRECATEDReturns an array of the object's children.clone(): Instance DEPRECATEDdestroy(): void DEPRECATEDfindFirstChild(name: string, recursive: boolean): Instance DEPRECATEDgetChildren(): Objects DEPRECATEDisA(className: string): boolean DEPRECATED, CUSTOM LUA STATEisDescendantOf(ancestor: Instance): boolean DEPRECATEDremove(): void DEPRECATEDEventsEvents inherited from BasePartLocalSimulationTouched(part: BasePart): RBXScriptSignal DEPRECATEDOutfitChanged(): RBXScriptSignal DEPRECATEDStoppedTouching(otherPart: BasePart): RBXScriptSignal DEPRECATEDTouchEnded(otherPart: BasePart): RBXScriptSignal Fires when a part stops touching another part as a result of physical |
| movement.Touched(otherPart: BasePart): RBXScriptSignal Fires when a part touches another part as a result of physical movement.Events inherited from InstanceAncestryChanged(child: Instance, parent: Instance): RBXScriptSignal Fires when the Instance.Parent property of the object or one of |
| its ancestors is changed.AttributeChanged(attribute: string): RBXScriptSignal Fires whenever an attribute is changed on the Instance.Changed(property: string): RBXScriptSignal Fired immediately after a property of an object changes.ChildAdded(child: Instance): RBXScriptSignal Fires after an object is parented to this Instance.ChildRemoved(child: Instance): RBXScriptSignal Fires after a child is removed from this Instance.DescendantAdded(descendant: Instance): RBXScriptSignal Fires after a descendant is added to the Instance.DescendantRemoving(descendant: Instance): RBXScriptSignal Fires immediately before a descendant of the Instance is removed.Destroying(): RBXScriptSignal Fires immediately before the instance is destroyed via |
| Instance:Destroy().childAdded(child: Instance): RBXScriptSignal DEPRECATEDPropertiesProperties inherited from PartShapePartTypeNot ReplicatedRead ParallelThe Shape property sets the overall shape of the object to one of a |
| predetermined list of built-in shapes. |
| The PartType enum controls the shape value, and has five possible |
| shapes: |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| Shape/ValueDescriptionBallA spherical shape, like a basketball.CylinderA rod-like shape, like a tin can.BlockThe default, brick shape.WedgeA wedge shape with a slope on one side.CornerWedgeA wedge shape with slopes on two sides. |
| Note that MeshPart and |
| solid modeling can be used to obtain |
| completely custom part shapes.Code SamplesThe script below spawns a new Part instance and sets several of the part's |
| properties. |
| Most notably, the script sets the Part.Shape property to |
| PartType.Ball. It also names the part JurassicPart, anchors it, makes |
| it a child of Workspace, and sets its color to white.Create a Part in a Scriptlocal part = Instance.new("Part") |
| part.Name = "JurassicPart" |
| part.Anchored = true |
| part.Shape = Enum.PartType.Ball |
| part.Color = Color3.new(1, 1, 1) |
| part.Parent = workspace -- Put the part into the WorkspaceProperties inherited from FormFactorPartFormFactorFormFactorNot ReplicatedDEPRECATEDRead ParallelDEPRECATEDThis property has been deprecated and should not be used in new work.This used to specify a grid constraint of the part's size. No longer does |
| anything.formFactorFormFactorHiddenNot ReplicatedDEPRECATEDRead ParallelDEPRECATEDThis property has been deprecated and should not be used in new work.Determines how a part acts when resized and the values that which its size |
| can take.Properties inherited from BasePartAnchoredbooleanRead ParallelThe Anchored property determines whether the part will be immovable by |
| physics. When enabled, a part will never change position due to gravity, |
| other parts collisions, overlapping other parts, or any other |
| physics-related causes. A part that is not anchored is called |
| unanchored. As a result, two anchored parts will never fire the |
| BasePart.Touched event on each other. An anchored part may still |
| be moved by changing its BasePart.CFrame or |
| BasePart.Position, and it still may have a nonzero |
| BasePart.AssemblyLinearVelocity and |
| BasePart.AssemblyAngularVelocity. Finally, if an unanchored part |
| is joined with an anchored part through an object like a Weld, it |
| too will act anchored. If such a joint breaks the part may be affected by |
| physics again. See |
| Understanding Assemblies for more on |
| this. |
| Network ownership cannot be set on anchored parts. If a part's anchored |
| status changes on the server, the network ownership of that part will be |
| affected.Code SamplesThis code sample will allow a part to be clicked to toggle its anchored property. When toggled, the visual appearance of the part is updated (red means anchored, yellow means free).Part Anchored Toggle |
| local part = script.Parent |
|
|
| -- Create a ClickDetector so we can tell when the part is clicked |
| local cd = Instance.new("ClickDetector", part) |
|
|
| -- This function updates how the part looks based on its Anchored state |
| local function updateVisuals() |
| if part.Anchored then |
| -- When the part is anchored... |
| part.BrickColor = BrickColor.new("Bright red") |
| part.Material = Enum.Material.DiamondPlate |
| else |
| -- When the part is unanchored... |
| part.BrickColor = BrickColor.new("Bright yellow") |
| part.Material = Enum.Material.Wood |
| end |
| end |
|
|
| local function onToggle() |
| -- Toggle the anchored property |
| part.Anchored = not part.Anchored |
| |
| -- Update visual state of the brick |
| updateVisuals() |
| end |
|
|
| -- Update, then start listening for clicks |
| updateVisuals() |
| cd.MouseClick:Connect(onToggle)AssemblyAngularVelocityVector3Not ReplicatedRead ParallelThe angular velocity vector of this part's assembly. It's |
| the rate of change of orientation in radians per second. |
| Angular velocity is the same at every point of the assembly. |
| Setting the velocity directly may lead to unrealistic motion. Using |
| Torque or AngularVelocity constraint is preferred, or use |
| BasePart:ApplyAngularImpulse() if you want instantaneous change in |
| velocity.AssemblyCenterOfMassVector3Read OnlyNot ReplicatedRead ParallelA position calculated via the mass and |
| position of all the parts in the assembly. |
| If the assembly has an anchored part, that part's center of mass will be |
| the assembly's center of mass, and the assembly will have infinite mass. |
| Knowing the center of mass can help the assembly maintain stability. A |
| force applied to the center of mass will not cause angular acceleration, |
| only linear. An assembly with a low center of mass will have a better time |
| staying upright under the effect of gravity.AssemblyLinearVelocityVector3Not ReplicatedRead ParallelThe linear velocity vector of this part's assembly. It's |
| the rate of change in position of the assembly's |
| center of mass in studs per second. |
| If you want to know the velocity at a point other than the assembly's |
| center of mass, use BasePart:GetVelocityAtPosition(). |
| Setting the velocity directly may lead to unrealistic motion. Using a |
| VectorForce constraint is preferred, or use |
| BasePart:ApplyImpulse() if you want instantaneous change in |
| velocity.AssemblyMassnumberRead OnlyNot ReplicatedRead ParallelThe sum of the mass of all the parts in this part's |
| assembly. Parts that are Massless and are not |
| the assembly's root part will not contribute to the AssemblyMass. |
| If the assembly has an anchored part, the assembly's mass is considered |
| infinite. Constraints and other physical interactions between unanchored |
| assemblies with a large difference in mass may cause instabilities.AssemblyRootPartBasePartRead OnlyNot ReplicatedRead ParallelThis property indicates the BasePart automatically chosen to |
| represent the Assembly|assembly's root part. It is the same part that's |
| returned when developers call |
| GetRootPart(). |
| The root part can be changed by changing the |
| RootPriority of the parts in the assembly. |
| Parts that all share the same AssemblyRootPart are in the same assembly. |
| For more information on root parts, see |
| Understanding Assemblies.BackParamAnumberHiddenDEPRECATEDRead ParallelThe BackParamA property is relevant when a part's |
| BasePart.BackSurface is set to Motor or SteppingMotor and |
| BasePart.BackSurfaceInput is set to Sin. It determines the |
| amplitude of the motor's rotational velocity, using the following |
| formula: |
| MotorVelocity = ParamA * math.sin(workspace.DistributedGameTime * ParamB) |
| There are no other usages for this property.Code SamplesThis code sample demonstrates how surface properties can be set using only a |
| NormalId (Top, Front, etc). It switches a motor's -SurfaceInput from NoInput, |
| Constant and Sin to show how each work using -ParamA and -ParamB properties.Motor Control-- Paste this into a Script inside a part with a Motor SurfaceType |
| local partMotor = script.Parent |
| -- Place a brick called "MovingPart" so it is touching the Motor surface |
|
|
| -- For this example, we use TopSurface, TopSurfaceInput, TopParamA and TopParamB |
| -- However, this will work for all faces (NormalId): Top, Bottom, Left, Right, Front and Back |
|
|
| -- A function to quickly set all surface properties at once |
| local function setFaceSurfaceInputParams(normalId, surfaceType, inputType, paramA, paramB) |
| local surfaceName = normalId.Name -- e.g. "Top", "Bottom", etc |
|
|
| -- Syntax Note: in Lua, part.Something is the same as part["Something"] |
| -- The difference is that the latter allows us to use a string ("Something"), while |
| -- the former requires use of an identifier (.Something). Below, we build of each the surface |
| -- properties below by concatenating the surface name with the property postfix. |
|
|
| -- Set "___Surface", eg "TopSurface" |
| partMotor[surfaceName .. "Surface"] = surfaceType |
| -- Set "___SurfaceInput", eg "TopSurfaceInput" |
| partMotor[surfaceName .. "SurfaceInput"] = inputType |
| -- Set "___ParamA", eg "TopParamA" |
| partMotor[surfaceName .. "ParamA"] = paramA |
| -- Set "___ParamB", eg "TopParamB" |
| partMotor[surfaceName .. "ParamB"] = paramB |
| end |
|
|
| local normalId = Enum.NormalId.Top |
|
|
| while true do |
| -- Set to NoInput, where the motor will not operate at all |
| setFaceSurfaceInputParams(normalId, Enum.SurfaceType.Motor, Enum.InputType.NoInput, 0, 0) |
| task.wait(1) |
| -- Set to Constant, where motor rotational velocity = paramB |
| setFaceSurfaceInputParams(normalId, Enum.SurfaceType.Motor, Enum.InputType.Constant, 0, 0.25) |
| task.wait(2) |
| -- Set to Sin, where motor rotational velocity = paramA * math.sin(time * paramB) |
| -- Since we're using pi (~3.14), the frequency of rotation is 1 second (per definition of sine function) |
| setFaceSurfaceInputParams(normalId, Enum.SurfaceType.Motor, Enum.InputType.Sin, 0.25, math.pi) |
| task.wait(3) |
| endBackParamBnumberHiddenDEPRECATEDRead ParallelThe BackParamB property is relevant when a part's |
| BasePart.BackSurface is set to Motor or SteppingMotor and |
| BasePart.BackSurfaceInput is set to Constant or Sin. For Constant, |
| it determines the constant rotational velocity of the motor. For Sin, it |
| determines the frequency of the motor's rotational velocity, using the |
| following formula: |
| MotorVelocity = ParamB * math.sin(workspace.DistributedGameTime * ParamB) |
| In no other cases is this property used.Code SamplesThis code sample demonstrates how surface properties can be set using only a |
| NormalId (Top, Front, etc). It switches a motor's -SurfaceInput from NoInput, |
| Constant and Sin to show how each work using -ParamA and -ParamB properties.Motor Control-- Paste this into a Script inside a part with a Motor SurfaceType |
| local partMotor = script.Parent |
| -- Place a brick called "MovingPart" so it is touching the Motor surface |
|
|
| -- For this example, we use TopSurface, TopSurfaceInput, TopParamA and TopParamB |
| -- However, this will work for all faces (NormalId): Top, Bottom, Left, Right, Front and Back |
|
|
| -- A function to quickly set all surface properties at once |
| local function setFaceSurfaceInputParams(normalId, surfaceType, inputType, paramA, paramB) |
| local surfaceName = normalId.Name -- e.g. "Top", "Bottom", etc |
|
|
| -- Syntax Note: in Lua, part.Something is the same as part["Something"] |
| -- The difference is that the latter allows us to use a string ("Something"), while |
| -- the former requires use of an identifier (.Something). Below, we build of each the surface |
| -- properties below by concatenating the surface name with the property postfix. |
|
|
| -- Set "___Surface", eg "TopSurface" |
| partMotor[surfaceName .. "Surface"] = surfaceType |
| -- Set "___SurfaceInput", eg "TopSurfaceInput" |
| partMotor[surfaceName .. "SurfaceInput"] = inputType |
| -- Set "___ParamA", eg "TopParamA" |
| partMotor[surfaceName .. "ParamA"] = paramA |
| -- Set "___ParamB", eg "TopParamB" |
| partMotor[surfaceName .. "ParamB"] = paramB |
| end |
|
|
| local normalId = Enum.NormalId.Top |
|
|
| while true do |
| -- Set to NoInput, where the motor will not operate at all |
| setFaceSurfaceInputParams(normalId, Enum.SurfaceType.Motor, Enum.InputType.NoInput, 0, 0) |
| task.wait(1) |
| -- Set to Constant, where motor rotational velocity = paramB |
| setFaceSurfaceInputParams(normalId, Enum.SurfaceType.Motor, Enum.InputType.Constant, 0, 0.25) |
| task.wait(2) |
| -- Set to Sin, where motor rotational velocity = paramA * math.sin(time * paramB) |
| -- Since we're using pi (~3.14), the frequency of rotation is 1 second (per definition of sine function) |
| setFaceSurfaceInputParams(normalId, Enum.SurfaceType.Motor, Enum.InputType.Sin, 0.25, math.pi) |
| task.wait(3) |
| endBackSurfaceSurfaceTypeRead ParallelThe BackSurface property determines the type of surface used for the +Z |
| direction of a part. When two parts' faces are placed next to each other, |
| they may create a joint between them. If set to Motor, the |
| BasePart.BackSurfaceInput determines how a motor joint should |
| behave. |
| Most SurfaceTypes render a texture on the part face if the |
| BasePart.Material is set to Plastic. Some SurfaceTypes - Hinge, |
| Motor and SteppingMotor - will render a 3D adornment instead. If this |
| property is selected in the Properties window, it will be highlighted in |
| the game world similar to that of a SurfaceSelection.Code SamplesThis code sample shows what each SurfaceType looks like on a part. In |
| addition, it creates a BillboardGui label on the part with a TextLabel that |
| reflects the name of the current SurfaceType.Show All SurfaceTypeslocal demoPart = script.Parent |
|
|
| -- Create a billboard gui to display what the current surface type is |
| local billboard = Instance.new("BillboardGui") |
| billboard.AlwaysOnTop = true |
| billboard.Size = UDim2.new(0, 200, 0, 50) |
| billboard.Adornee = demoPart |
| local textLabel = Instance.new("TextLabel") |
| textLabel.Size = UDim2.new(0, 200, 0, 50) |
| textLabel.BackgroundTransparency = 1 |
| textLabel.TextStrokeTransparency = 0 |
| textLabel.TextColor3 = Color3.new(1, 1, 1) -- White |
| textLabel.Parent = billboard |
| billboard.Parent = demoPart |
|
|
| local function setAllSurfaces(part, surfaceType) |
| part.TopSurface = surfaceType |
| part.BottomSurface = surfaceType |
| part.LeftSurface = surfaceType |
| part.RightSurface = surfaceType |
| part.FrontSurface = surfaceType |
| part.BackSurface = surfaceType |
| end |
|
|
| while true do |
| -- Iterate through the different SurfaceTypes |
| for _, enum in pairs(Enum.SurfaceType:GetEnumItems()) do |
| textLabel.Text = enum.Name |
| setAllSurfaces(demoPart, enum) |
| task.wait(1) |
| end |
| endBackSurfaceInputInputTypeHiddenDEPRECATEDRead ParallelThe BackSurfaceInput property determines the kind of input provided to a |
| part's BasePart.BackSurface. This is only relevant for Motor or |
| SteppingMotor SurfaceTypes. This property determines how |
| BasePart.BackParamA and BasePart.BackParamB are used. For |
| brevity, these properties will be referred to as ParamA and ParamB, |
| respectively. |
|
|
| By default, this is set to NoInput. This stops the motor altogether. |
| For Constant, the motor rotates at a constant velocity equal to |
| ParamB. |
| For Sin, the motor rotates at a velocity equal to |
| ParamA * math.sin(workspace.DistributedGameTime * ParamB). See |
| Workspace.DistributedGameTime. |
| Code SamplesThis code sample demonstrates how surface properties can be set using only a |
| NormalId (Top, Front, etc). It switches a motor's -SurfaceInput from NoInput, |
| Constant and Sin to show how each work using -ParamA and -ParamB properties.Motor Control-- Paste this into a Script inside a part with a Motor SurfaceType |
| local partMotor = script.Parent |
| -- Place a brick called "MovingPart" so it is touching the Motor surface |
|
|
| -- For this example, we use TopSurface, TopSurfaceInput, TopParamA and TopParamB |
| -- However, this will work for all faces (NormalId): Top, Bottom, Left, Right, Front and Back |
|
|
| -- A function to quickly set all surface properties at once |
| local function setFaceSurfaceInputParams(normalId, surfaceType, inputType, paramA, paramB) |
| local surfaceName = normalId.Name -- e.g. "Top", "Bottom", etc |
|
|
| -- Syntax Note: in Lua, part.Something is the same as part["Something"] |
| -- The difference is that the latter allows us to use a string ("Something"), while |
| -- the former requires use of an identifier (.Something). Below, we build of each the surface |
| -- properties below by concatenating the surface name with the property postfix. |
|
|
| -- Set "___Surface", eg "TopSurface" |
| partMotor[surfaceName .. "Surface"] = surfaceType |
| -- Set "___SurfaceInput", eg "TopSurfaceInput" |
| partMotor[surfaceName .. "SurfaceInput"] = inputType |
| -- Set "___ParamA", eg "TopParamA" |
| partMotor[surfaceName .. "ParamA"] = paramA |
| -- Set "___ParamB", eg "TopParamB" |
| partMotor[surfaceName .. "ParamB"] = paramB |
| end |
|
|
| local normalId = Enum.NormalId.Top |
|
|
| while true do |
| -- Set to NoInput, where the motor will not operate at all |
| setFaceSurfaceInputParams(normalId, Enum.SurfaceType.Motor, Enum.InputType.NoInput, 0, 0) |
| task.wait(1) |
| -- Set to Constant, where motor rotational velocity = paramB |
| setFaceSurfaceInputParams(normalId, Enum.SurfaceType.Motor, Enum.InputType.Constant, 0, 0.25) |
| task.wait(2) |
| -- Set to Sin, where motor rotational velocity = paramA * math.sin(time * paramB) |
| -- Since we're using pi (~3.14), the frequency of rotation is 1 second (per definition of sine function) |
| setFaceSurfaceInputParams(normalId, Enum.SurfaceType.Motor, Enum.InputType.Sin, 0.25, math.pi) |
| task.wait(3) |
| endBottomParamAnumberHiddenDEPRECATEDRead ParallelThe BottomParamA property is relevant when a part's |
| BasePart.BottomSurface is set to Motor or SteppingMotor and |
| BasePart.BottomSurfaceInput is set to Sin. It determines the |
| amplitude of the motor's rotational velocity, using the following |
| formula: |
| MotorVelocity = ParamA * math.sin(workspace.DistributedGameTime * ParamB) |
| There are no other usages for this property.Code SamplesThis code sample demonstrates how surface properties can be set using only a |
| NormalId (Top, Front, etc). It switches a motor's -SurfaceInput from NoInput, |
| Constant and Sin to show how each work using -ParamA and -ParamB properties.Motor Control-- Paste this into a Script inside a part with a Motor SurfaceType |
| local partMotor = script.Parent |
| -- Place a brick called "MovingPart" so it is touching the Motor surface |
|
|
| -- For this example, we use TopSurface, TopSurfaceInput, TopParamA and TopParamB |
| -- However, this will work for all faces (NormalId): Top, Bottom, Left, Right, Front and Back |
|
|
| -- A function to quickly set all surface properties at once |
| local function setFaceSurfaceInputParams(normalId, surfaceType, inputType, paramA, paramB) |
| local surfaceName = normalId.Name -- e.g. "Top", "Bottom", etc |
|
|
| -- Syntax Note: in Lua, part.Something is the same as part["Something"] |
| -- The difference is that the latter allows us to use a string ("Something"), while |
| -- the former requires use of an identifier (.Something). Below, we build of each the surface |
| -- properties below by concatenating the surface name with the property postfix. |
|
|
| -- Set "___Surface", eg "TopSurface" |
| partMotor[surfaceName .. "Surface"] = surfaceType |
| -- Set "___SurfaceInput", eg "TopSurfaceInput" |
| partMotor[surfaceName .. "SurfaceInput"] = inputType |
| -- Set "___ParamA", eg "TopParamA" |
| partMotor[surfaceName .. "ParamA"] = paramA |
| -- Set "___ParamB", eg "TopParamB" |
| partMotor[surfaceName .. "ParamB"] = paramB |
| end |
|
|
| local normalId = Enum.NormalId.Top |
|
|
| while true do |
| -- Set to NoInput, where the motor will not operate at all |
| setFaceSurfaceInputParams(normalId, Enum.SurfaceType.Motor, Enum.InputType.NoInput, 0, 0) |
| task.wait(1) |
| -- Set to Constant, where motor rotational velocity = paramB |
| setFaceSurfaceInputParams(normalId, Enum.SurfaceType.Motor, Enum.InputType.Constant, 0, 0.25) |
| task.wait(2) |
| -- Set to Sin, where motor rotational velocity = paramA * math.sin(time * paramB) |
| -- Since we're using pi (~3.14), the frequency of rotation is 1 second (per definition of sine function) |
| setFaceSurfaceInputParams(normalId, Enum.SurfaceType.Motor, Enum.InputType.Sin, 0.25, math.pi) |
| task.wait(3) |
| endBottomParamBnumberHiddenDEPRECATEDRead ParallelThe BottomParamB property is relevant when a part's |
| BasePart.BottomSurface is set to Motor or SteppingMotor and |
| BasePart.BottomSurfaceInput is set to Constant or Sin. For |
| Constant, it determines the constant rotational velocity of the motor. For |
| Sin, it determines the frequency of the motor's rotational velocity, |
| using the following formula: |
| MotorVelocity = ParamB * math.sin(workspace.DistributedGameTime * ParamB) |
| In no other cases is this property used.Code SamplesThis code sample demonstrates how surface properties can be set using only a |
| NormalId (Top, Front, etc). It switches a motor's -SurfaceInput from NoInput, |
| Constant and Sin to show how each work using -ParamA and -ParamB properties.Motor Control-- Paste this into a Script inside a part with a Motor SurfaceType |
| local partMotor = script.Parent |
| -- Place a brick called "MovingPart" so it is touching the Motor surface |
|
|
| -- For this example, we use TopSurface, TopSurfaceInput, TopParamA and TopParamB |
| -- However, this will work for all faces (NormalId): Top, Bottom, Left, Right, Front and Back |
|
|
| -- A function to quickly set all surface properties at once |
| local function setFaceSurfaceInputParams(normalId, surfaceType, inputType, paramA, paramB) |
| local surfaceName = normalId.Name -- e.g. "Top", "Bottom", etc |
|
|
| -- Syntax Note: in Lua, part.Something is the same as part["Something"] |
| -- The difference is that the latter allows us to use a string ("Something"), while |
| -- the former requires use of an identifier (.Something). Below, we build of each the surface |
| -- properties below by concatenating the surface name with the property postfix. |
|
|
| -- Set "___Surface", eg "TopSurface" |
| partMotor[surfaceName .. "Surface"] = surfaceType |
| -- Set "___SurfaceInput", eg "TopSurfaceInput" |
| partMotor[surfaceName .. "SurfaceInput"] = inputType |
| -- Set "___ParamA", eg "TopParamA" |
| partMotor[surfaceName .. "ParamA"] = paramA |
| -- Set "___ParamB", eg "TopParamB" |
| partMotor[surfaceName .. "ParamB"] = paramB |
| end |
|
|
| local normalId = Enum.NormalId.Top |
|
|
| while true do |
| -- Set to NoInput, where the motor will not operate at all |
| setFaceSurfaceInputParams(normalId, Enum.SurfaceType.Motor, Enum.InputType.NoInput, 0, 0) |
| task.wait(1) |
| -- Set to Constant, where motor rotational velocity = paramB |
| setFaceSurfaceInputParams(normalId, Enum.SurfaceType.Motor, Enum.InputType.Constant, 0, 0.25) |
| task.wait(2) |
| -- Set to Sin, where motor rotational velocity = paramA * math.sin(time * paramB) |
| -- Since we're using pi (~3.14), the frequency of rotation is 1 second (per definition of sine function) |
| setFaceSurfaceInputParams(normalId, Enum.SurfaceType.Motor, Enum.InputType.Sin, 0.25, math.pi) |
| task.wait(3) |
| endBottomSurfaceSurfaceTypeRead ParallelThe BottomSurface property determines the type of surface used for the -Y |
| direction of a part. When two parts' faces are placed next to each other, |
| they may create a joint between them. If set to Motor, the |
| BasePart.BottomSurfaceInput determines how a motor joint should |
| behave. |
| Most SurfaceTypes render a texture on the part face if the |
| BasePart.Material is set to Plastic. Some SurfaceTypes - Hinge, |
| Motor and SteppingMotor - will render a 3D adornment instead. If this |
| property is selected in the Properties window, it will be highlighted in |
| the game world similar to that of a SurfaceSelection.Code SamplesThis code sample shows what each SurfaceType looks like on a part. In |
| addition, it creates a BillboardGui label on the part with a TextLabel that |
| reflects the name of the current SurfaceType.Show All SurfaceTypeslocal demoPart = script.Parent |
|
|
| -- Create a billboard gui to display what the current surface type is |
| local billboard = Instance.new("BillboardGui") |
| billboard.AlwaysOnTop = true |
| billboard.Size = UDim2.new(0, 200, 0, 50) |
| billboard.Adornee = demoPart |
| local textLabel = Instance.new("TextLabel") |
| textLabel.Size = UDim2.new(0, 200, 0, 50) |
| textLabel.BackgroundTransparency = 1 |
| textLabel.TextStrokeTransparency = 0 |
| textLabel.TextColor3 = Color3.new(1, 1, 1) -- White |
| textLabel.Parent = billboard |
| billboard.Parent = demoPart |
|
|
| local function setAllSurfaces(part, surfaceType) |
| part.TopSurface = surfaceType |
| part.BottomSurface = surfaceType |
| part.LeftSurface = surfaceType |
| part.RightSurface = surfaceType |
| part.FrontSurface = surfaceType |
| part.BackSurface = surfaceType |
| end |
|
|
| while true do |
| -- Iterate through the different SurfaceTypes |
| for _, enum in pairs(Enum.SurfaceType:GetEnumItems()) do |
| textLabel.Text = enum.Name |
| setAllSurfaces(demoPart, enum) |
| task.wait(1) |
| end |
| endBottomSurfaceInputInputTypeHiddenDEPRECATEDRead ParallelThe BottomSurfaceInput property determines the kind of input provided to a |
| part's BasePart.BottomSurface. This is only relevant for Motor or |
| SteppingMotor SurfaceTypes. This property determines how |
| BasePart.BottomParamA and BasePart.BottomParamB are used. |
| For brevity, these properties will be referred to as ParamA and ParamB, |
| respectively. |
|
|
| By default, this is set to NoInput. This stops the motor altogether. |
| For Constant, the motor rotates at a constant velocity equal to |
| ParamB. |
| For Sin, the motor rotates at a velocity equal to |
| ParamA * math.sin(workspace.DistributedGameTime * ParamB). See |
| Workspace.DistributedGameTime. |
| Code SamplesThis code sample demonstrates how surface properties can be set using only a |
| NormalId (Top, Front, etc). It switches a motor's -SurfaceInput from NoInput, |
| Constant and Sin to show how each work using -ParamA and -ParamB properties.Motor Control-- Paste this into a Script inside a part with a Motor SurfaceType |
| local partMotor = script.Parent |
| -- Place a brick called "MovingPart" so it is touching the Motor surface |
|
|
| -- For this example, we use TopSurface, TopSurfaceInput, TopParamA and TopParamB |
| -- However, this will work for all faces (NormalId): Top, Bottom, Left, Right, Front and Back |
|
|
| -- A function to quickly set all surface properties at once |
| local function setFaceSurfaceInputParams(normalId, surfaceType, inputType, paramA, paramB) |
| local surfaceName = normalId.Name -- e.g. "Top", "Bottom", etc |
|
|
| -- Syntax Note: in Lua, part.Something is the same as part["Something"] |
| -- The difference is that the latter allows us to use a string ("Something"), while |
| -- the former requires use of an identifier (.Something). Below, we build of each the surface |
| -- properties below by concatenating the surface name with the property postfix. |
|
|
| -- Set "___Surface", eg "TopSurface" |
| partMotor[surfaceName .. "Surface"] = surfaceType |
| -- Set "___SurfaceInput", eg "TopSurfaceInput" |
| partMotor[surfaceName .. "SurfaceInput"] = inputType |
| -- Set "___ParamA", eg "TopParamA" |
| partMotor[surfaceName .. "ParamA"] = paramA |
| -- Set "___ParamB", eg "TopParamB" |
| partMotor[surfaceName .. "ParamB"] = paramB |
| end |
|
|
| local normalId = Enum.NormalId.Top |
|
|
| while true do |
| -- Set to NoInput, where the motor will not operate at all |
| setFaceSurfaceInputParams(normalId, Enum.SurfaceType.Motor, Enum.InputType.NoInput, 0, 0) |
| task.wait(1) |
| -- Set to Constant, where motor rotational velocity = paramB |
| setFaceSurfaceInputParams(normalId, Enum.SurfaceType.Motor, Enum.InputType.Constant, 0, 0.25) |
| task.wait(2) |
| -- Set to Sin, where motor rotational velocity = paramA * math.sin(time * paramB) |
| -- Since we're using pi (~3.14), the frequency of rotation is 1 second (per definition of sine function) |
| setFaceSurfaceInputParams(normalId, Enum.SurfaceType.Motor, Enum.InputType.Sin, 0.25, math.pi) |
| task.wait(3) |
| endBrickColorBrickColorNot ReplicatedRead ParallelThe BrickColor property determines the color of a part. If the part has a |
| BasePart.Material, this also determines the color used when |
| rendering the material texture. For more control over the color, the |
| BasePart.Color property can be used (it is a Color3 variant of |
| this property). If Color set, this property will use the closest |
| BrickColor. |
| Other visual properties of a part are determined by |
| BasePart.Transparency and BasePart.Reflectance.Code SamplesThis code sample will allow a part to be clicked to toggle its anchored property. When toggled, the visual appearance of the part is updated (red means anchored, yellow means free).Part Anchored Toggle |
| local part = script.Parent |
|
|
| -- Create a ClickDetector so we can tell when the part is clicked |
| local cd = Instance.new("ClickDetector", part) |
|
|
| -- This function updates how the part looks based on its Anchored state |
| local function updateVisuals() |
| if part.Anchored then |
| -- When the part is anchored... |
| part.BrickColor = BrickColor.new("Bright red") |
| part.Material = Enum.Material.DiamondPlate |
| else |
| -- When the part is unanchored... |
| part.BrickColor = BrickColor.new("Bright yellow") |
| part.Material = Enum.Material.Wood |
| end |
| end |
|
|
| local function onToggle() |
| -- Toggle the anchored property |
| part.Anchored = not part.Anchored |
| |
| -- Update visual state of the brick |
| updateVisuals() |
| end |
|
|
| -- Update, then start listening for clicks |
| updateVisuals() |
| cd.MouseClick:Connect(onToggle)CFrameCFrameRead ParallelThe CFrame property determines both the position and orientation of |
| the BasePart in the world. It acts as an arbitrary reference |
| location on the geometry, but ExtentsCFrame |
| represents the actual CFrame of its physical center. |
| When setting CFrame on a part, other joined parts are also moved |
| relative to the part, but it is recommended that you use |
| PVInstance:PivotTo() to move an entire model, such as when |
| teleporting a player's character. |
| Unlike setting BasePart.Position, setting BasePart.CFrame |
| will always move the part to the exact given CFrame; in other |
| words: no overlap checking is done and the physics solver will attempt |
| to resolve any overlap unless both parts are |
| Anchored. |
| For keeping track of positions relative to a part's CFrame, an |
| Attachment may be useful.Code SamplesThis code sample demonstrates setting a part's CFrame in many different ways. |
| It showcases how to create and compose CFrame values. It references a sibling |
| part called "OtherPart" for demonstrating relative positioning.Setting Part CFramelocal part = script.Parent |
|
|
| -- Reset the part's CFrame to (0, 0, 0) with no rotation. |
| -- This is sometimes called the "identity" CFrame |
| part.CFrame = CFrame.new() |
|
|
| -- Set to a specific position (X, Y, Z) |
| part.CFrame = CFrame.new(0, 25, 10) |
|
|
| -- Same as above, but use a Vector3 instead |
| local point = Vector3.new(0, 25, 10) |
| part.CFrame = CFrame.new(point) |
|
|
| -- Set the part's CFrame to be at one point, looking at another |
| local lookAtPoint = Vector3.new(0, 20, 15) |
| part.CFrame = CFrame.new(point, lookAtPoint) |
|
|
| -- Rotate the part's CFrame by pi/2 radians on local X axis |
| part.CFrame = part.CFrame * CFrame.Angles(math.pi / 2, 0, 0) |
| -- Rotate the part's CFrame by 45 degrees on local Y axis |
| part.CFrame = part.CFrame * CFrame.Angles(0, math.rad(45), 0) |
| -- Rotate the part's CFrame by 180 degrees on global Z axis (note the order!) |
| part.CFrame = CFrame.Angles(0, 0, math.pi) * part.CFrame -- Pi radians is equal to 180 degrees |
|
|
| -- Composing two CFrames is done using * (the multiplication operator) |
| part.CFrame = CFrame.new(2, 3, 4) * CFrame.new(4, 5, 6) --> equal to CFrame.new(6, 8, 10) |
|
|
| -- Unlike algebraic multiplication, CFrame composition is NOT communitative: a * b is not necessarily b * a! |
| -- Imagine * as an ORDERED series of actions. For example, the following lines produce different CFrames: |
| -- 1) Slide the part 5 units on X. |
| -- 2) Rotate the part 45 degrees around its Y axis. |
| part.CFrame = CFrame.new(5, 0, 0) * CFrame.Angles(0, math.rad(45), 0) |
| -- 1) Rotate the part 45 degrees around its Y axis. |
| -- 2) Slide the part 5 units on X. |
| part.CFrame = CFrame.Angles(0, math.rad(45), 0) * CFrame.new(5, 0, 0) |
|
|
| -- There is no "CFrame division", but instead simply "doing the inverse operation". |
| part.CFrame = CFrame.new(4, 5, 6) * CFrame.new(4, 5, 6):inverse() --> is equal to CFrame.new(0, 0, 0) |
| part.CFrame = CFrame.Angles(0, 0, math.pi) * CFrame.Angles(0, 0, math.pi):inverse() --> equal to CFrame.Angles(0, 0, 0) |
|
|
| -- A reference to some other part |
| local otherPart = part.Parent.OtherPart |
|
|
| -- Position a part relative to another (in this case, put our part on top of otherPart) |
| part.CFrame = otherPart.CFrame * CFrame.new(0, part.Size.Y / 2 + otherPart.Size.Y / 2, 0) |
|
|
| -- All of this information applies to SetPrimaryPartCFrame, since that's all tht method |
| local model = part.Parent.Model |
| model:SetPrimaryPartCFrame(CFrame.new(0, 25, 0))CanCollidebooleanRead ParallelCanCollide determines whether a part will physically interact with other |
| parts. When disabled, other parts can pass through the brick |
| uninterrupted. Parts used for decoration usually have CanCollide |
| disabled, as they need not be considered by the physics engine. |
| If a part is not BasePart.Anchored and has CanCollide disabled, it |
| may fall out of the world to be eventually destroyed by |
| Workspace.FallenPartsDestroyHeight. |
| When CanCollide is disabled, parts may still fire the |
| BasePart.Touched event (as well the other parts touching them). |
| You can disable this with BasePart.CanTouch. |
| For more information on collisions, see |
| Collisions.Code SamplesThis code sample shows how a part can fade away when touched by a Humanoid |
| then reappear a moment after to create a passable door.Fade Door-- Paste into a Script inside a tall part |
| local part = script.Parent |
|
|
| local OPEN_TIME = 1 |
|
|
| -- Can the door be opened at the moment? |
| local debounce = false |
|
|
| local function open() |
| part.CanCollide = false |
| part.Transparency = 0.7 |
| part.BrickColor = BrickColor.new("Black") |
| end |
|
|
| local function close() |
| part.CanCollide = true |
| part.Transparency = 0 |
| part.BrickColor = BrickColor.new("Bright blue") |
| end |
|
|
| local function onTouch(otherPart) |
| -- If the door was already open, do nothing |
| if debounce then |
| print("D") |
| return |
| end |
|
|
| -- Check if touched by a Humanoid |
| local human = otherPart.Parent:FindFirstChildOfClass("Humanoid") |
| if not human then |
| print("not human") |
| return |
| end |
|
|
| -- Perform the door opening sequence |
| debounce = true |
| open() |
| task.wait(OPEN_TIME) |
| close() |
| debounce = false |
| end |
|
|
| part.Touched:Connect(onTouch) |
| close()CanQuerybooleanRead ParallelCanQuery determines whether the part is considered during spatial query |
| operations, such as |
| GetPartBoundsInBox or |
| Raycast. CanCollide must also be disabled |
| when disabling CanQuery. These functions will never include parts whose |
| CanQuery and CanCollide is false. |
| Beyond this property, it is also possible to exclude parts which are |
| descendants of a given list of parts using an OverlapParams or |
| RaycastParams object when calling the spatial query functions.CanTouchbooleanRead ParallelThis property determines if Touched and |
| TouchEnded events fire on the part. If true, |
| other touching parts must also have CanTouch set |
| to true for touch events to fire. If false, touch events cannot be set |
| up for the part and attempting to do so will throw an error. Similarly, if |
| the property is set to false after a touch event is connected, the event |
| will be disconnected and the TouchTransmitter removed. |
| Note that this collision logic can be set to respect |
| collision groups |
| through the Workspace.TouchesUseCollisionGroups property. If |
| true, parts in non-colliding groups will ignore both collisions and |
| touch events, thereby making this property irrelevant. |
| Performance |
| There is a small performance gain on parts that have both |
| CanTouch and |
| CanCollide set to false, as these parts will |
| never need to compute any kind of part to part collisions. However, they |
| can still be hit by Raycasts and |
| OverlapParams queries.CastShadowbooleanRead ParallelDetermines whether or not a part casts a shadow. |
| Note that this feature is not designed for performance enhancement. It |
| should only be disabled on parts where you want to hide the shadows the |
| part casts. Disabling this property for a given part may cause visual |
| artifacts on the shadows cast upon that part.CenterOfMassVector3Read OnlyNot ReplicatedRead ParallelThe CenterOfMass property describes the local position of a |
| part's center of mass. If this is a single part assembly, |
| this is the AssemblyCenterOfMass converted from world space to local. On |
| simple Parts, the center of mass is always (0,0,0). It can |
| vary for WedgePart or MeshPart however.CollisionGroupstringNot ReplicatedRead ParallelThe CollisionGroup property describes the |
| name of the part's collision group (maximum of 100 characters). Parts |
| start off in the default group whose name is "Default". This value |
| cannot be empty.Code SamplesThis example demonstrates one basic use of collision groups. It assigns |
| BallPart to "CollisionGroupBall" and DoorPart to |
| "CollisionGroupDoor", then makes the two groups non-collidable using |
| PhysicsService:CollisionGroupSetCollidable().PhysicsService:RegisterCollisionGrouplocal PhysicsService = game:GetService("PhysicsService") |
|
|
| local collisionGroupBall = "CollisionGroupBall" |
| local collisionGroupDoor = "CollisionGroupDoor" |
|
|
| -- Register collision groups |
| PhysicsService:RegisterCollisionGroup(collisionGroupBall) |
| PhysicsService:RegisterCollisionGroup(collisionGroupDoor) |
|
|
| -- Assign parts to collision groups |
| workspace.BallPart.CollisionGroup = collisionGroupBall |
| workspace.DoorPart.CollisionGroup = collisionGroupDoor |
|
|
| -- Set groups as non-collidable and check the result |
| PhysicsService:CollisionGroupSetCollidable(collisionGroupBall, collisionGroupDoor, false) |
| print(PhysicsService:CollisionGroupsAreCollidable(collisionGroupBall, collisionGroupDoor)) --> falseCollisionGroupIdnumberNot ReplicatedDEPRECATEDRead ParallelThe BasePart.CollisionGroupId property describes the ID number of |
| the part's collision group. Parts start off in the "Default" group whose |
| ID is 0. If a part is unregistered, the value becomes -1. This value |
| cannot be less than -1 and it cannot exceed |
| PhysicsService:GetMaxCollisionGroups(). Invalid IDs are clamped. |
| Although this property can be directly changed, it's recommended that you |
| specify the collision group by setting BasePart.CollisionGroup to |
| the collision group's name.ColorColor3Not ReplicatedRead ParallelThe Color property determines the color of a part. If the part has a |
| BasePart.Material, this also determines the color used when |
| rendering the material texture. If this property is set, |
| BasePart.BrickColor will use the closest BrickColor to the Color3 |
| value. |
| Other visual properties of a part are determined by |
| BasePart.Transparency and BasePart.Reflectance.Code SamplesThis code sample colors a player's entire character based on how much health |
| they have. It generates a color based on their max health, then sets the color |
| properties of objects within their character, removing any extra objects.Character Health Body Color-- Paste into a Script within StarterCharacterScripts |
| -- Then play the game, and fiddle with your character's health |
| local char = script.Parent |
| local human = char.Humanoid |
|
|
| local colorHealthy = Color3.new(0.4, 1, 0.2) |
| local colorUnhealthy = Color3.new(1, 0.4, 0.2) |
|
|
| local function setColor(color) |
| for _, child in pairs(char:GetChildren()) do |
| if child:IsA("BasePart") then |
| child.Color = color |
| while child:FindFirstChildOfClass("Decal") do |
| child:FindFirstChildOfClass("Decal"):Destroy() |
| end |
| elseif child:IsA("Accessory") then |
| child.Handle.Color = color |
| local mesh = child.Handle:FindFirstChildOfClass("SpecialMesh") |
| if mesh then |
| mesh.TextureId = "" |
| end |
| elseif child:IsA("Shirt") or child:IsA("Pants") then |
| child:Destroy() |
| end |
| end |
| end |
|
|
| local function update() |
| local percentage = human.Health / human.MaxHealth |
|
|
| -- Create a color by tweening based on the percentage of your health |
| -- The color goes from colorHealthy (100%) ----- > colorUnhealthy (0%) |
| local color = Color3.new( |
| colorHealthy.R * percentage + colorUnhealthy.r * (1 - percentage), |
| colorHealthy.G * percentage + colorUnhealthy.g * (1 - percentage), |
| colorHealthy.B * percentage + colorUnhealthy.b * (1 - percentage) |
| ) |
| setColor(color) |
| end |
|
|
| update() |
| human.HealthChanged:Connect(update)CurrentPhysicalPropertiesPhysicalPropertiesRead OnlyNot ReplicatedRead ParallelCurrentPhysicalProperties indicates the current physical properties of the |
| part. You can set custom values for the physical properties per part, |
| custom material, and material override. The |
| Engine prioritizes more granular definitions when determining the |
| effective physical properties of a part. The values in the following list |
| are in order from highest to lowest priority: |
|
|
| Custom physical properties of the part |
| Custom physical properties of the part's custom material |
| Custom physical properties of the material override of the part's |
| material |
| Default physical properties of the part's material |
| CustomPhysicalPropertiesPhysicalPropertiesRead ParallelCustomPhysicalProperties lets you customize various physical aspects of a |
| Part, such as its density, friction, and elasticity. |
| If enabled, this property let's you configure these physical properties. |
| If disabled, these physical properties are determined by the |
| BasePart.Material of the part. The page for Material |
| contains list of the various part materials.Code SamplesThis code sample demonstrates how to set the CustomPhysicalProperties property |
| of a part.Set CustomPhysicalPropertieslocal part = script.Parent |
|
|
| -- This will make the part light and bouncy! |
| local DENSITY = 0.3 |
| local FRICTION = 0.1 |
| local ELASTICITY = 1 |
| local FRICTION_WEIGHT = 1 |
| local ELASTICITY_WEIGHT = 1 |
|
|
| local physProperties = PhysicalProperties.new(DENSITY, FRICTION, ELASTICITY, FRICTION_WEIGHT, ELASTICITY_WEIGHT) |
| part.CustomPhysicalProperties = physPropertiesElasticitynumberHiddenNot ReplicatedDEPRECATEDRead ParallelDEPRECATEDThis is only one of multiple physics-related properties. It has been |
| deprecated in favor of BasePart.CustomPhysicalProperties, which |
| combines these properties into one.The Elasticity of a part is now determined by either its Material |
| or its CustomPhysicalProperties.EnableFluidForcesbooleanRead ParallelWhen true, and when Workspace.FluidForces is enabled, causes the |
| physics engine to compute aerodynamic forces on this BasePart.ExtentsCFrameCFrameRead OnlyNot ReplicatedRead ParallelThe CFrame of the physical extents of the BasePart, |
| representing its physical center.ExtentsSizeVector3Read OnlyNot ReplicatedRead ParallelThe actual physical size of the BasePart as regarded by the |
| physics engine, for example in |
| collision detection.FrictionnumberHiddenNot ReplicatedDEPRECATEDRead ParallelDEPRECATEDThis is only one of multiple physics-related properties. It has been |
| deprecated in favor of BasePart.CustomPhysicalProperties, which |
| combines these properties into one.Used to control the Friction of the part, but now it no longer does |
| anything. The Friction of a part is now determined by either its |
| Material or its |
| CustomPhysicalProperties.FrontParamAnumberHiddenDEPRECATEDRead ParallelThe FrontParamA property is relevant when a part's |
| BasePart.FrontSurface is set to Motor or SteppingMotor and |
| BasePart.FrontSurfaceInput is set to Sin. It determines the |
| amplitude of the motor's rotational velocity, using the following |
| formula: |
| MotorVelocity = ParamA * math.sin(workspace.DistributedGameTime * ParamB) |
| In no other cases is this property used.Code SamplesThis code sample demonstrates how surface properties can be set using only a |
| NormalId (Top, Front, etc). It switches a motor's -SurfaceInput from NoInput, |
| Constant and Sin to show how each work using -ParamA and -ParamB properties.Motor Control-- Paste this into a Script inside a part with a Motor SurfaceType |
| local partMotor = script.Parent |
| -- Place a brick called "MovingPart" so it is touching the Motor surface |
|
|
| -- For this example, we use TopSurface, TopSurfaceInput, TopParamA and TopParamB |
| -- However, this will work for all faces (NormalId): Top, Bottom, Left, Right, Front and Back |
|
|
| -- A function to quickly set all surface properties at once |
| local function setFaceSurfaceInputParams(normalId, surfaceType, inputType, paramA, paramB) |
| local surfaceName = normalId.Name -- e.g. "Top", "Bottom", etc |
|
|
| -- Syntax Note: in Lua, part.Something is the same as part["Something"] |
| -- The difference is that the latter allows us to use a string ("Something"), while |
| -- the former requires use of an identifier (.Something). Below, we build of each the surface |
| -- properties below by concatenating the surface name with the property postfix. |
|
|
| -- Set "___Surface", eg "TopSurface" |
| partMotor[surfaceName .. "Surface"] = surfaceType |
| -- Set "___SurfaceInput", eg "TopSurfaceInput" |
| partMotor[surfaceName .. "SurfaceInput"] = inputType |
| -- Set "___ParamA", eg "TopParamA" |
| partMotor[surfaceName .. "ParamA"] = paramA |
| -- Set "___ParamB", eg "TopParamB" |
| partMotor[surfaceName .. "ParamB"] = paramB |
| end |
|
|
| local normalId = Enum.NormalId.Top |
|
|
| while true do |
| -- Set to NoInput, where the motor will not operate at all |
| setFaceSurfaceInputParams(normalId, Enum.SurfaceType.Motor, Enum.InputType.NoInput, 0, 0) |
| task.wait(1) |
| -- Set to Constant, where motor rotational velocity = paramB |
| setFaceSurfaceInputParams(normalId, Enum.SurfaceType.Motor, Enum.InputType.Constant, 0, 0.25) |
| task.wait(2) |
| -- Set to Sin, where motor rotational velocity = paramA * math.sin(time * paramB) |
| -- Since we're using pi (~3.14), the frequency of rotation is 1 second (per definition of sine function) |
| setFaceSurfaceInputParams(normalId, Enum.SurfaceType.Motor, Enum.InputType.Sin, 0.25, math.pi) |
| task.wait(3) |
| endFrontParamBnumberHiddenDEPRECATEDRead ParallelThe FrontParamB property is relevant when a part's |
| BasePart.FrontSurface is set to Motor or SteppingMotor and |
| BasePart.FrontSurfaceInput is set to Constant or Sin. For |
| Constant, it determines the constant rotational velocity of the motor. For |
| Sin, it determines the frequency of the motor's rotational velocity, |
| using the following formula: |
| MotorVelocity = ParamB * math.sin(workspace.DistributedGameTime * ParamB) |
| In no other cases is this property used.Code SamplesThis code sample demonstrates how surface properties can be set using only a |
| NormalId (Top, Front, etc). It switches a motor's -SurfaceInput from NoInput, |
| Constant and Sin to show how each work using -ParamA and -ParamB properties.Motor Control-- Paste this into a Script inside a part with a Motor SurfaceType |
| local partMotor = script.Parent |
| -- Place a brick called "MovingPart" so it is touching the Motor surface |
|
|
| -- For this example, we use TopSurface, TopSurfaceInput, TopParamA and TopParamB |
| -- However, this will work for all faces (NormalId): Top, Bottom, Left, Right, Front and Back |
|
|
| -- A function to quickly set all surface properties at once |
| local function setFaceSurfaceInputParams(normalId, surfaceType, inputType, paramA, paramB) |
| local surfaceName = normalId.Name -- e.g. "Top", "Bottom", etc |
|
|
| -- Syntax Note: in Lua, part.Something is the same as part["Something"] |
| -- The difference is that the latter allows us to use a string ("Something"), while |
| -- the former requires use of an identifier (.Something). Below, we build of each the surface |
| -- properties below by concatenating the surface name with the property postfix. |
|
|
| -- Set "___Surface", eg "TopSurface" |
| partMotor[surfaceName .. "Surface"] = surfaceType |
| -- Set "___SurfaceInput", eg "TopSurfaceInput" |
| partMotor[surfaceName .. "SurfaceInput"] = inputType |
| -- Set "___ParamA", eg "TopParamA" |
| partMotor[surfaceName .. "ParamA"] = paramA |
| -- Set "___ParamB", eg "TopParamB" |
| partMotor[surfaceName .. "ParamB"] = paramB |
| end |
|
|
| local normalId = Enum.NormalId.Top |
|
|
| while true do |
| -- Set to NoInput, where the motor will not operate at all |
| setFaceSurfaceInputParams(normalId, Enum.SurfaceType.Motor, Enum.InputType.NoInput, 0, 0) |
| task.wait(1) |
| -- Set to Constant, where motor rotational velocity = paramB |
| setFaceSurfaceInputParams(normalId, Enum.SurfaceType.Motor, Enum.InputType.Constant, 0, 0.25) |
| task.wait(2) |
| -- Set to Sin, where motor rotational velocity = paramA * math.sin(time * paramB) |
| -- Since we're using pi (~3.14), the frequency of rotation is 1 second (per definition of sine function) |
| setFaceSurfaceInputParams(normalId, Enum.SurfaceType.Motor, Enum.InputType.Sin, 0.25, math.pi) |
| task.wait(3) |
| endFrontSurfaceSurfaceTypeRead ParallelThe FrontSurface property determines the type of surface used for the -Z |
| direction of a part. When two parts' faces are placed next to each other, |
| they may create a joint between them. If set to Motor, the |
| BasePart.FrontSurfaceInput determines how a motor joint should |
| behave. |
| Most SurfaceTypes render a texture on the part face if the |
| BasePart.Material is set to Plastic. Some SurfaceTypes including |
| Hinge, Motor, and SteppingMotor render a 3D adornment instead. If this |
| property is selected in the Properties window, it will be highlighted in |
| the game world similar to that of a SurfaceSelection.Code SamplesThis code sample shows what each SurfaceType looks like on a part. In |
| addition, it creates a BillboardGui label on the part with a TextLabel that |
| reflects the name of the current SurfaceType.Show All SurfaceTypeslocal demoPart = script.Parent |
|
|
| -- Create a billboard gui to display what the current surface type is |
| local billboard = Instance.new("BillboardGui") |
| billboard.AlwaysOnTop = true |
| billboard.Size = UDim2.new(0, 200, 0, 50) |
| billboard.Adornee = demoPart |
| local textLabel = Instance.new("TextLabel") |
| textLabel.Size = UDim2.new(0, 200, 0, 50) |
| textLabel.BackgroundTransparency = 1 |
| textLabel.TextStrokeTransparency = 0 |
| textLabel.TextColor3 = Color3.new(1, 1, 1) -- White |
| textLabel.Parent = billboard |
| billboard.Parent = demoPart |
|
|
| local function setAllSurfaces(part, surfaceType) |
| part.TopSurface = surfaceType |
| part.BottomSurface = surfaceType |
| part.LeftSurface = surfaceType |
| part.RightSurface = surfaceType |
| part.FrontSurface = surfaceType |
| part.BackSurface = surfaceType |
| end |
|
|
| while true do |
| -- Iterate through the different SurfaceTypes |
| for _, enum in pairs(Enum.SurfaceType:GetEnumItems()) do |
| textLabel.Text = enum.Name |
| setAllSurfaces(demoPart, enum) |
| task.wait(1) |
| end |
| endFrontSurfaceInputInputTypeHiddenDEPRECATEDRead ParallelThe FrontSurfaceInput property determines the kind of input provided to a |
| part's BasePart.FrontSurface. This is only relevant for Motor or |
| SteppingMotor SurfaceTypes. This property determines how |
| BasePart.FrontParamA and BasePart.FrontParamB are used. |
| For brevity, these properties will be referred to as ParamA and ParamB, |
| respectively. |
|
|
| By default, this is set to NoInput. This stops the motor altogether. |
| For Constant, the motor rotates at a constant velocity equal to |
| ParamB. |
| For Sin, the motor rotates at a velocity equal to |
| ParamA * math.sin(workspace.DistributedGameTime * ParamB). See |
| Workspace.DistributedGameTime. |
| Code SamplesThis code sample demonstrates how surface properties can be set using only a |
| NormalId (Top, Front, etc). It switches a motor's -SurfaceInput from NoInput, |
| Constant and Sin to show how each work using -ParamA and -ParamB properties.Motor Control-- Paste this into a Script inside a part with a Motor SurfaceType |
| local partMotor = script.Parent |
| -- Place a brick called "MovingPart" so it is touching the Motor surface |
|
|
| -- For this example, we use TopSurface, TopSurfaceInput, TopParamA and TopParamB |
| -- However, this will work for all faces (NormalId): Top, Bottom, Left, Right, Front and Back |
|
|
| -- A function to quickly set all surface properties at once |
| local function setFaceSurfaceInputParams(normalId, surfaceType, inputType, paramA, paramB) |
| local surfaceName = normalId.Name -- e.g. "Top", "Bottom", etc |
|
|
| -- Syntax Note: in Lua, part.Something is the same as part["Something"] |
| -- The difference is that the latter allows us to use a string ("Something"), while |
| -- the former requires use of an identifier (.Something). Below, we build of each the surface |
| -- properties below by concatenating the surface name with the property postfix. |
|
|
| -- Set "___Surface", eg "TopSurface" |
| partMotor[surfaceName .. "Surface"] = surfaceType |
| -- Set "___SurfaceInput", eg "TopSurfaceInput" |
| partMotor[surfaceName .. "SurfaceInput"] = inputType |
| -- Set "___ParamA", eg "TopParamA" |
| partMotor[surfaceName .. "ParamA"] = paramA |
| -- Set "___ParamB", eg "TopParamB" |
| partMotor[surfaceName .. "ParamB"] = paramB |
| end |
|
|
| local normalId = Enum.NormalId.Top |
|
|
| while true do |
| -- Set to NoInput, where the motor will not operate at all |
| setFaceSurfaceInputParams(normalId, Enum.SurfaceType.Motor, Enum.InputType.NoInput, 0, 0) |
| task.wait(1) |
| -- Set to Constant, where motor rotational velocity = paramB |
| setFaceSurfaceInputParams(normalId, Enum.SurfaceType.Motor, Enum.InputType.Constant, 0, 0.25) |
| task.wait(2) |
| -- Set to Sin, where motor rotational velocity = paramA * math.sin(time * paramB) |
| -- Since we're using pi (~3.14), the frequency of rotation is 1 second (per definition of sine function) |
| setFaceSurfaceInputParams(normalId, Enum.SurfaceType.Motor, Enum.InputType.Sin, 0.25, math.pi) |
| task.wait(3) |
| endLeftParamAnumberHiddenDEPRECATEDRead ParallelThe LeftParamA property is relevant when a part's |
| BasePart.LeftSurface is set to Motor or SteppingMotor and |
| BasePart.LeftSurfaceInput is set to Sin. It determines the |
| amplitude of the motor's rotational velocity, using the following |
| formula: |
| MotorVelocity = ParamA * math.sin(workspace.DistributedGameTime * ParamB) |
| In no other cases is this property used.Code SamplesThis code sample demonstrates how surface properties can be set using only a |
| NormalId (Top, Front, etc). It switches a motor's -SurfaceInput from NoInput, |
| Constant and Sin to show how each work using -ParamA and -ParamB properties.Motor Control-- Paste this into a Script inside a part with a Motor SurfaceType |
| local partMotor = script.Parent |
| -- Place a brick called "MovingPart" so it is touching the Motor surface |
|
|
| -- For this example, we use TopSurface, TopSurfaceInput, TopParamA and TopParamB |
| -- However, this will work for all faces (NormalId): Top, Bottom, Left, Right, Front and Back |
|
|
| -- A function to quickly set all surface properties at once |
| local function setFaceSurfaceInputParams(normalId, surfaceType, inputType, paramA, paramB) |
| local surfaceName = normalId.Name -- e.g. "Top", "Bottom", etc |
|
|
| -- Syntax Note: in Lua, part.Something is the same as part["Something"] |
| -- The difference is that the latter allows us to use a string ("Something"), while |
| -- the former requires use of an identifier (.Something). Below, we build of each the surface |
| -- properties below by concatenating the surface name with the property postfix. |
|
|
| -- Set "___Surface", eg "TopSurface" |
| partMotor[surfaceName .. "Surface"] = surfaceType |
| -- Set "___SurfaceInput", eg "TopSurfaceInput" |
| partMotor[surfaceName .. "SurfaceInput"] = inputType |
| -- Set "___ParamA", eg "TopParamA" |
| partMotor[surfaceName .. "ParamA"] = paramA |
| -- Set "___ParamB", eg "TopParamB" |
| partMotor[surfaceName .. "ParamB"] = paramB |
| end |
|
|
| local normalId = Enum.NormalId.Top |
|
|
| while true do |
| -- Set to NoInput, where the motor will not operate at all |
| setFaceSurfaceInputParams(normalId, Enum.SurfaceType.Motor, Enum.InputType.NoInput, 0, 0) |
| task.wait(1) |
| -- Set to Constant, where motor rotational velocity = paramB |
| setFaceSurfaceInputParams(normalId, Enum.SurfaceType.Motor, Enum.InputType.Constant, 0, 0.25) |
| task.wait(2) |
| -- Set to Sin, where motor rotational velocity = paramA * math.sin(time * paramB) |
| -- Since we're using pi (~3.14), the frequency of rotation is 1 second (per definition of sine function) |
| setFaceSurfaceInputParams(normalId, Enum.SurfaceType.Motor, Enum.InputType.Sin, 0.25, math.pi) |
| task.wait(3) |
| endLeftParamBnumberHiddenDEPRECATEDRead ParallelThe LeftParamB property is relevant when a part's |
| BasePart.LeftSurface is set to Motor or SteppingMotor and |
| BasePart.LeftSurfaceInput is set to Constant or Sin. For Constant, |
| it determines the constant rotational velocity of the motor. For Sin, it |
| determines the frequency of the motor's rotational velocity, using the |
| following formula: |
| MotorVelocity = ParamB * math.sin(workspace.DistributedGameTime * ParamB) |
| In no other cases is this property used.Code SamplesThis code sample demonstrates how surface properties can be set using only a |
| NormalId (Top, Front, etc). It switches a motor's -SurfaceInput from NoInput, |
| Constant and Sin to show how each work using -ParamA and -ParamB properties.Motor Control-- Paste this into a Script inside a part with a Motor SurfaceType |
| local partMotor = script.Parent |
| -- Place a brick called "MovingPart" so it is touching the Motor surface |
|
|
| -- For this example, we use TopSurface, TopSurfaceInput, TopParamA and TopParamB |
| -- However, this will work for all faces (NormalId): Top, Bottom, Left, Right, Front and Back |
|
|
| -- A function to quickly set all surface properties at once |
| local function setFaceSurfaceInputParams(normalId, surfaceType, inputType, paramA, paramB) |
| local surfaceName = normalId.Name -- e.g. "Top", "Bottom", etc |
|
|
| -- Syntax Note: in Lua, part.Something is the same as part["Something"] |
| -- The difference is that the latter allows us to use a string ("Something"), while |
| -- the former requires use of an identifier (.Something). Below, we build of each the surface |
| -- properties below by concatenating the surface name with the property postfix. |
|
|
| -- Set "___Surface", eg "TopSurface" |
| partMotor[surfaceName .. "Surface"] = surfaceType |
| -- Set "___SurfaceInput", eg "TopSurfaceInput" |
| partMotor[surfaceName .. "SurfaceInput"] = inputType |
| -- Set "___ParamA", eg "TopParamA" |
| partMotor[surfaceName .. "ParamA"] = paramA |
| -- Set "___ParamB", eg "TopParamB" |
| partMotor[surfaceName .. "ParamB"] = paramB |
| end |
|
|
| local normalId = Enum.NormalId.Top |
|
|
| while true do |
| -- Set to NoInput, where the motor will not operate at all |
| setFaceSurfaceInputParams(normalId, Enum.SurfaceType.Motor, Enum.InputType.NoInput, 0, 0) |
| task.wait(1) |
| -- Set to Constant, where motor rotational velocity = paramB |
| setFaceSurfaceInputParams(normalId, Enum.SurfaceType.Motor, Enum.InputType.Constant, 0, 0.25) |
| task.wait(2) |
| -- Set to Sin, where motor rotational velocity = paramA * math.sin(time * paramB) |
| -- Since we're using pi (~3.14), the frequency of rotation is 1 second (per definition of sine function) |
| setFaceSurfaceInputParams(normalId, Enum.SurfaceType.Motor, Enum.InputType.Sin, 0.25, math.pi) |
| task.wait(3) |
| endLeftSurfaceSurfaceTypeRead ParallelThe LeftSurface property determines the type of surface used for the -X |
| direction of a part. When two parts' faces are placed next to each other, |
| they may create a joint between them. If set to Motor, the |
| BasePart.LeftSurfaceInput determines how a motor joint should |
| behave. |
| Most SurfaceTypes render a texture on the part face if the |
| BasePart.Material is set to Plastic. Some SurfaceTypes including |
| Hinge, Motor, and SteppingMotor render a 3D adornment instead. If this |
| property is selected in the Properties window, it will be highlighted in |
| the game world similar to that of a SurfaceSelection.Code SamplesThis code sample shows what each SurfaceType looks like on a part. In |
| addition, it creates a BillboardGui label on the part with a TextLabel that |
| reflects the name of the current SurfaceType.Show All SurfaceTypeslocal demoPart = script.Parent |
|
|
| -- Create a billboard gui to display what the current surface type is |
| local billboard = Instance.new("BillboardGui") |
| billboard.AlwaysOnTop = true |
| billboard.Size = UDim2.new(0, 200, 0, 50) |
| billboard.Adornee = demoPart |
| local textLabel = Instance.new("TextLabel") |
| textLabel.Size = UDim2.new(0, 200, 0, 50) |
| textLabel.BackgroundTransparency = 1 |
| textLabel.TextStrokeTransparency = 0 |
| textLabel.TextColor3 = Color3.new(1, 1, 1) -- White |
| textLabel.Parent = billboard |
| billboard.Parent = demoPart |
|
|
| local function setAllSurfaces(part, surfaceType) |
| part.TopSurface = surfaceType |
| part.BottomSurface = surfaceType |
| part.LeftSurface = surfaceType |
| part.RightSurface = surfaceType |
| part.FrontSurface = surfaceType |
| part.BackSurface = surfaceType |
| end |
|
|
| while true do |
| -- Iterate through the different SurfaceTypes |
| for _, enum in pairs(Enum.SurfaceType:GetEnumItems()) do |
| textLabel.Text = enum.Name |
| setAllSurfaces(demoPart, enum) |
| task.wait(1) |
| end |
| endLeftSurfaceInputInputTypeHiddenDEPRECATEDRead ParallelThe LeftSurfaceInput property determines the kind of input provided to a |
| part's BasePart.LeftSurface. This is only relevant for Motor or |
| SteppingMotor SurfaceTypes. This property determines how |
| BasePart.LeftParamA and BasePart.LeftParamB are used. For |
| brevity, these properties will be referred to as ParamA and ParamB, |
| respectively. |
|
|
| By default, this is set to NoInput. This stops the motor altogether. |
| For Constant, the motor rotates at a constant velocity equal to |
| ParamB. |
| For Sin, the motor rotates at a velocity equal to |
| ParamA * math.sin(workspace.DistributedGameTime * ParamB). See |
| Workspace.DistributedGameTime. |
| Code SamplesThis code sample demonstrates how surface properties can be set using only a |
| NormalId (Top, Front, etc). It switches a motor's -SurfaceInput from NoInput, |
| Constant and Sin to show how each work using -ParamA and -ParamB properties.Motor Control-- Paste this into a Script inside a part with a Motor SurfaceType |
| local partMotor = script.Parent |
| -- Place a brick called "MovingPart" so it is touching the Motor surface |
|
|
| -- For this example, we use TopSurface, TopSurfaceInput, TopParamA and TopParamB |
| -- However, this will work for all faces (NormalId): Top, Bottom, Left, Right, Front and Back |
|
|
| -- A function to quickly set all surface properties at once |
| local function setFaceSurfaceInputParams(normalId, surfaceType, inputType, paramA, paramB) |
| local surfaceName = normalId.Name -- e.g. "Top", "Bottom", etc |
|
|
| -- Syntax Note: in Lua, part.Something is the same as part["Something"] |
| -- The difference is that the latter allows us to use a string ("Something"), while |
| -- the former requires use of an identifier (.Something). Below, we build of each the surface |
| -- properties below by concatenating the surface name with the property postfix. |
|
|
| -- Set "___Surface", eg "TopSurface" |
| partMotor[surfaceName .. "Surface"] = surfaceType |
| -- Set "___SurfaceInput", eg "TopSurfaceInput" |
| partMotor[surfaceName .. "SurfaceInput"] = inputType |
| -- Set "___ParamA", eg "TopParamA" |
| partMotor[surfaceName .. "ParamA"] = paramA |
| -- Set "___ParamB", eg "TopParamB" |
| partMotor[surfaceName .. "ParamB"] = paramB |
| end |
|
|
| local normalId = Enum.NormalId.Top |
|
|
| while true do |
| -- Set to NoInput, where the motor will not operate at all |
| setFaceSurfaceInputParams(normalId, Enum.SurfaceType.Motor, Enum.InputType.NoInput, 0, 0) |
| task.wait(1) |
| -- Set to Constant, where motor rotational velocity = paramB |
| setFaceSurfaceInputParams(normalId, Enum.SurfaceType.Motor, Enum.InputType.Constant, 0, 0.25) |
| task.wait(2) |
| -- Set to Sin, where motor rotational velocity = paramA * math.sin(time * paramB) |
| -- Since we're using pi (~3.14), the frequency of rotation is 1 second (per definition of sine function) |
| setFaceSurfaceInputParams(normalId, Enum.SurfaceType.Motor, Enum.InputType.Sin, 0.25, math.pi) |
| task.wait(3) |
| endLocalTransparencyModifiernumberHiddenNot ReplicatedRead ParallelThe LocalTransparencyModifier |
| property is a multiplier to BasePart.Transparency that is only |
| visible to the local client. It does not replicate from client to server |
| and is useful for when a part should not render for a specific client, |
| such as how the player does not see their character's body parts when they |
| zoom into first person mode. |
| This property modifies the local part's transparency through the following |
| formula, with resulting values clamped between 0 and 1. |
| clientTransparency = 1 - ((1 - part.Transparency) * (1 - part.LocalTransparencyModifier)) |
| TransparencyLocalTransparencyModifierServer-Side TransparencyClient-Side Transparency0.500.50.50.50.250.50.6250.50.50.50.750.50.750.50.8750.510.51LockedbooleanRead ParallelThe Locked property determines whether a part (or a |
| model it is contained within) may be selected in Roblox |
| Studio by clicking on it. This property is most often enabled on parts |
| within environment models that aren't being edited at the moment. Roblox |
| Studio has a Lock/Unlock All tool that can toggle the Locked state of |
| every part descendant in a model at once.Code SamplesThis code sample uses the concept of recursion to unlock all parts that are a |
| descendant of a model.Recursive Unlock-- Paste into a Script within a Model you want to unlock |
| local model = script.Parent |
|
|
| -- This function recurses through a model's heirarchy and unlocks |
| -- every part that it encounters. |
| local function recursiveUnlock(object) |
| if object:IsA("BasePart") then |
| object.Locked = false |
| end |
|
|
| -- Call the same function on the children of the object |
| -- The recursive process stops if an object has no children |
| for _, child in pairs(object:GetChildren()) do |
| recursiveUnlock(child) |
| end |
| end |
|
|
| recursiveUnlock(model)MassnumberRead OnlyNot ReplicatedRead ParallelMass is a read-only property that describes the product of a part's |
| volume and density. It is returned by the |
| GetMass function. |
|
|
| The volume of a part is determined by its Size and |
| its Shape, which varies depending on the kind of |
| BasePart used, such as WedgePart. |
| The density of a part is determined by its |
| Material or |
| CustomPhysicalProperties, if |
| specified. |
| MasslessbooleanRead ParallelIf this property is enabled, the BasePart will not |
| contribute to the total mass or inertia of its assembly as long as it is |
| welded to another part that has mass. |
| If the part is its own root part according to |
| AssemblyRootPart, this will be ignored |
| for that part, and it will still contribute mass and inertia to its |
| assembly like a normal part. Parts that are massless should never become |
| an assembly root part unless all other parts in the assembly are also |
| massless. |
| This might be useful for things like optional accessories on vehicles that |
| you don't want to affect the handling of the car or a massless render mesh |
| welded to a simpler collision mesh. |
| See also Understanding Assemblies, an |
| article documenting what root parts are and how to use them.MaterialMaterialRead ParallelThe Material property allows a builder to set a part's texture and default |
| physical properties (in the case that |
| BasePart.CustomPhysicalProperties is unset). The default Plastic |
| material has a very light texture, and the SmoothPlastic material has no |
| texture at all. Some material textures like DiamondPlate and Granite have |
| very visible textures. Each material's texture reflects sunlight |
| differently, especially Foil. |
| Setting this property then enabling |
| BasePart.CustomPhysicalProperties will use the default physical |
| properties of a material. For instance, DiamondPlate is a very dense |
| material while Wood is very light. A part's density determines whether it |
| will float in terrain water. |
| The Glass material changes rendering behavior on moderate graphics |
| settings. It applies a bit of reflectiveness (similar to |
| BasePart.Reflectance) and perspective distortion. The effect is |
| especially pronounced on sphere-shaped parts (set BasePart.Shape |
| to Ball). Semitransparent objects and Glass parts behind Glass are not |
| visible.Code SamplesThis code sample will allow a part to be clicked to toggle its anchored property. When toggled, the visual appearance of the part is updated (red means anchored, yellow means free).Part Anchored Toggle |
| local part = script.Parent |
|
|
| -- Create a ClickDetector so we can tell when the part is clicked |
| local cd = Instance.new("ClickDetector", part) |
|
|
| -- This function updates how the part looks based on its Anchored state |
| local function updateVisuals() |
| if part.Anchored then |
| -- When the part is anchored... |
| part.BrickColor = BrickColor.new("Bright red") |
| part.Material = Enum.Material.DiamondPlate |
| else |
| -- When the part is unanchored... |
| part.BrickColor = BrickColor.new("Bright yellow") |
| part.Material = Enum.Material.Wood |
| end |
| end |
|
|
| local function onToggle() |
| -- Toggle the anchored property |
| part.Anchored = not part.Anchored |
| |
| -- Update visual state of the brick |
| updateVisuals() |
| end |
|
|
| -- Update, then start listening for clicks |
| updateVisuals() |
| cd.MouseClick:Connect(onToggle)MaterialVariantstringNot ReplicatedRead ParallelThe system searches the MaterialVariant instance with specified |
| MaterialVariant name and BasePart.Material type. If it |
| successfully finds a matching MaterialVariant instance, it uses this |
| MaterialVariant instance to replace the default material. Default material |
| can be the built-in material or an override MaterialVariant specified in |
| MaterialService.OrientationVector3HiddenNot ReplicatedRead ParallelThe Orientation property describes the part's rotation in degrees around |
| the X, Y and Z axes using a Vector3. The rotations are applied in Y → X → |
| Z order. This differs from proper Euler angles and is instead |
| Tait-Bryan angles, which describe yaw, pitch and roll. It is also |
| worth noting how this property differs from the CFrame.Angles() |
| constructor, which applies rotations in a different order (Z → Y → X). For |
| better control over the rotation of a part, it is recommended that |
| BasePart.CFrame is set instead. |
| When setting this property any Welds or |
| Motor6Ds connected to this part will have the matching |
| C0 or C1 property |
| updated and to allow the part to move relative to any other parts it is |
| joined to. |
| WeldConstraints will also be temporarily disabled and re-enabled during |
| the move.Code SamplesThis code sample rotates a part continually on the Y axis.Part Spinnerlocal part = script.Parent |
|
|
| local INCREMENT = 360 / 20 |
|
|
| -- Rotate the part continually |
| while true do |
| for degrees = 0, 360, INCREMENT do |
| -- Set only the Y axis rotation |
| part.Rotation = Vector3.new(0, degrees, 0) |
| -- A better way to do this would be setting CFrame |
| --part.CFrame = CFrame.new(part.Position) * CFrame.Angles(0, math.rad(degrees), 0) |
| task.wait() |
| end |
| endPivotOffsetCFrameRead ParallelThis property specifies the offset of the part's pivot from its |
| CFrame, that is part:GetPivot() is the same as |
| part.CFrame * part.PivotOffset. |
| This is convenient for setting the pivot to a location in local space, |
| but setting a part's pivot to a location in world space can be done as |
| follows: |
| local part = workspace.BluePart |
| local desiredPivotCFrameInWorldSpace = CFrame.new(0, 10, 0) |
| part.PivotOffset = part.CFrame:ToObjectSpace(desiredPivotCFrameInWorldSpace)Code SamplesThis code sample shows a custom function for resetting the pivot of a model |
| back to the center of that model's bounding box.Reset Pivotlocal function resetPivot(model) |
| local boundsCFrame = model:GetBoundingBox() |
| if model.PrimaryPart then |
| model.PrimaryPart.PivotOffset = model.PrimaryPart.CFrame:ToObjectSpace(boundsCFrame) |
| else |
| model.WorldPivot = boundsCFrame |
| end |
| end |
|
|
| resetPivot(script.Parent)This code sample creates a clock at the origin with a minute, second, and hour |
| hand, and makes it tick, displaying the local time.Clock Handslocal function createHand(length, width, yOffset) |
| local part = Instance.new("Part") |
| part.Size = Vector3.new(width, 0.1, length) |
| part.Material = Enum.Material.Neon |
| part.PivotOffset = CFrame.new(0, -(yOffset + 0.1), length / 2) |
| part.Anchored = true |
| part.Parent = workspace |
| return part |
| end |
|
|
| local function positionHand(hand, fraction) |
| hand:PivotTo(CFrame.fromEulerAnglesXYZ(0, -fraction * 2 * math.pi, 0)) |
| end |
|
|
| -- Create dial |
| for i = 0, 11 do |
| local dialPart = Instance.new("Part") |
| dialPart.Size = Vector3.new(0.2, 0.2, 1) |
| dialPart.TopSurface = Enum.SurfaceType.Smooth |
| if i == 0 then |
| dialPart.Size = Vector3.new(0.2, 0.2, 2) |
| dialPart.Color = Color3.new(1, 0, 0) |
| end |
| dialPart.PivotOffset = CFrame.new(0, -0.1, 10.5) |
| dialPart.Anchored = true |
| dialPart:PivotTo(CFrame.fromEulerAnglesXYZ(0, (i / 12) * 2 * math.pi, 0)) |
| dialPart.Parent = workspace |
| end |
|
|
| -- Create hands |
| local hourHand = createHand(7, 1, 0) |
| local minuteHand = createHand(10, 0.6, 0.1) |
| local secondHand = createHand(11, 0.2, 0.2) |
|
|
| -- Run clock |
| while true do |
| local components = os.date("*t") |
| positionHand(hourHand, (components.hour + components.min / 60) / 12) |
| positionHand(minuteHand, (components.min + components.sec / 60) / 60) |
| positionHand(secondHand, components.sec / 60) |
| task.wait() |
| endPositionVector3HiddenNot ReplicatedRead ParallelThe Position property describes the coordinates of a part |
| using a Vector3. It reflects the position of the part's |
| BasePart.CFrame, however it can also be set. |
| When setting this property any Welds or |
| Motor6Ds connected to this part will have the matching |
| C0 or C1 property |
| updated and to allow the part to move relative to any other parts it is |
| joined to. |
| WeldConstraints will also be temporarily disabled and re-enabled during |
| the move.ReceiveAgenumberHiddenRead OnlyNot ReplicatedRead ParallelThis returns the time in seconds since the part's physics got last updated |
| on the local client (or the server). Returns 0 when the part has no |
| physics (Anchored)ReflectancenumberRead ParallelThe Reflectance property determines how much a part |
| reflects the skybox. A value of 0 indicates the part is not reflective at |
| all, and a value of 1 indicates the part should fully reflect. |
| Reflectance is not affected by BasePart.Transparency, unless the |
| part is fully transparent, in which case reflectance will not render at |
| all. Reflectance may or may not be ignored depending on the |
| BasePart.Material of the part.Code SamplesThis code sample causes a part to blink its Reflectance and a PointLight every |
| time it is touched. It uses a pattern that prevents multiple concurrent |
| function calls from fighting with each other.Touch Blinklocal part = script.Parent |
|
|
| local pointLight = Instance.new("PointLight") |
| pointLight.Brightness = 0 |
| pointLight.Range = 12 |
| pointLight.Parent = part |
|
|
| local touchNo = 0 |
| local function blink() |
| -- Advance touchNo to tell other blink() calls to stop early |
| touchNo = touchNo + 1 |
| -- Save touchNo locally so we can tell when it changes globally |
| local myTouchNo = touchNo |
| for i = 1, 0, -0.1 do |
| -- Stop early if another blink started |
| if touchNo ~= myTouchNo then |
| break |
| end |
| -- Update the blink animation |
| part.Reflectance = i |
| pointLight.Brightness = i * 2 |
| task.wait(0.05) |
| end |
| end |
|
|
| part.Touched:Connect(blink)ResizeIncrementnumberRead OnlyNot ReplicatedRead ParallelThe ResizeIncrement property is a read-only property that describes the |
| smallest change in size allowable by the BasePart:Resize() method. |
| It differs between implementations of the BasePart abstract class. |
| For instance, Part has this set to 1 and TrussPart has |
| this set to 2 (since individual truss sections are 2x2x2 in size).Code SamplesThis code sample creates a Handles object and shows how to set the Faces |
| property of the object. It also references ResizeableFaces of a part. Try |
| placing this script in multiple kinds of parts to see how ResizeableFaces |
| varies.Resize Handles-- Put this Script in several kinds of BasePart, like |
| -- Part, TrussPart, WedgePart, CornerWedgePart, etc. |
| local part = script.Parent |
|
|
| -- Create a handles object for this part |
| local handles = Instance.new("Handles") |
| handles.Adornee = part |
| handles.Parent = part |
|
|
| -- Manually specify the faces applicable for this handle |
| handles.Faces = Faces.new(Enum.NormalId.Top, Enum.NormalId.Front, Enum.NormalId.Left) |
|
|
| -- Alternatively, use the faces on which the part can be resized. |
| -- If part is a TrussPart with only two Size dimensions |
| -- of length 2, then ResizeableFaces will only have two |
| -- enabled faces. For other parts, all faces will be enabled. |
| handles.Faces = part.ResizeableFacesResizeableFacesFacesRead OnlyNot ReplicatedRead ParallelThe ResizeableFaces property (with an e, not ResizableFaces) describes |
| using a Faces object the different faces on which a part may be resized. |
| For most implementations of BasePart, such as Part and |
| WedgePart, this property includes all faces. However, |
| TrussPart will set its ResizeableFaces set to only two faces since |
| those kinds of parts must have two BasePart.Size dimensions of |
| length 2. This property is most commonly used with tools used for building |
| and manipulating parts and has little use outside of that context. The |
| Handles class, which has the Handles.Faces property, can |
| be used in conjunction with this property to display only the handles on |
| faces that can be resized on a part.Code SamplesThis code sample creates a Handles object and shows how to set the Faces |
| property of the object. It also references ResizeableFaces of a part. Try |
| placing this script in multiple kinds of parts to see how ResizeableFaces |
| varies.Resize Handles-- Put this Script in several kinds of BasePart, like |
| -- Part, TrussPart, WedgePart, CornerWedgePart, etc. |
| local part = script.Parent |
|
|
| -- Create a handles object for this part |
| local handles = Instance.new("Handles") |
| handles.Adornee = part |
| handles.Parent = part |
|
|
| -- Manually specify the faces applicable for this handle |
| handles.Faces = Faces.new(Enum.NormalId.Top, Enum.NormalId.Front, Enum.NormalId.Left) |
|
|
| -- Alternatively, use the faces on which the part can be resized. |
| -- If part is a TrussPart with only two Size dimensions |
| -- of length 2, then ResizeableFaces will only have two |
| -- enabled faces. For other parts, all faces will be enabled. |
| handles.Faces = part.ResizeableFacesRightParamAnumberHiddenDEPRECATEDRead ParallelThe RightParamA property is relevant when a part's |
| BasePart.RightSurface is set to Motor or SteppingMotor and |
| BasePart.RightSurfaceInput is set to Sin. It determines the |
| amplitude of the motor's rotational velocity, using the following |
| formula: |
| MotorVelocity = ParamA * math.sin(workspace.DistributedGameTime * ParamB) |
| In no other cases is this property used.Code SamplesThis code sample demonstrates how surface properties can be set using only a |
| NormalId (Top, Front, etc). It switches a motor's -SurfaceInput from NoInput, |
| Constant and Sin to show how each work using -ParamA and -ParamB properties.Motor Control-- Paste this into a Script inside a part with a Motor SurfaceType |
| local partMotor = script.Parent |
| -- Place a brick called "MovingPart" so it is touching the Motor surface |
|
|
| -- For this example, we use TopSurface, TopSurfaceInput, TopParamA and TopParamB |
| -- However, this will work for all faces (NormalId): Top, Bottom, Left, Right, Front and Back |
|
|
| -- A function to quickly set all surface properties at once |
| local function setFaceSurfaceInputParams(normalId, surfaceType, inputType, paramA, paramB) |
| local surfaceName = normalId.Name -- e.g. "Top", "Bottom", etc |
|
|
| -- Syntax Note: in Lua, part.Something is the same as part["Something"] |
| -- The difference is that the latter allows us to use a string ("Something"), while |
| -- the former requires use of an identifier (.Something). Below, we build of each the surface |
| -- properties below by concatenating the surface name with the property postfix. |
|
|
| -- Set "___Surface", eg "TopSurface" |
| partMotor[surfaceName .. "Surface"] = surfaceType |
| -- Set "___SurfaceInput", eg "TopSurfaceInput" |
| partMotor[surfaceName .. "SurfaceInput"] = inputType |
| -- Set "___ParamA", eg "TopParamA" |
| partMotor[surfaceName .. "ParamA"] = paramA |
| -- Set "___ParamB", eg "TopParamB" |
| partMotor[surfaceName .. "ParamB"] = paramB |
| end |
|
|
| local normalId = Enum.NormalId.Top |
|
|
| while true do |
| -- Set to NoInput, where the motor will not operate at all |
| setFaceSurfaceInputParams(normalId, Enum.SurfaceType.Motor, Enum.InputType.NoInput, 0, 0) |
| task.wait(1) |
| -- Set to Constant, where motor rotational velocity = paramB |
| setFaceSurfaceInputParams(normalId, Enum.SurfaceType.Motor, Enum.InputType.Constant, 0, 0.25) |
| task.wait(2) |
| -- Set to Sin, where motor rotational velocity = paramA * math.sin(time * paramB) |
| -- Since we're using pi (~3.14), the frequency of rotation is 1 second (per definition of sine function) |
| setFaceSurfaceInputParams(normalId, Enum.SurfaceType.Motor, Enum.InputType.Sin, 0.25, math.pi) |
| task.wait(3) |
| endRightParamBnumberHiddenDEPRECATEDRead ParallelThe RightParamB property is relevant when a part's |
| BasePart.RightSurface is set to Motor or SteppingMotor and |
| BasePart.RightSurfaceInput is set to Constant or Sin. For |
| Constant, it determines the constant rotational velocity of the motor. For |
| Sin, it determines the frequency of the motor's rotational velocity, |
| using the following formula: |
| MotorVelocity = ParamB * math.sin(workspace.DistributedGameTime * ParamB) |
| In no other cases is this property used.Code SamplesThis code sample demonstrates how surface properties can be set using only a |
| NormalId (Top, Front, etc). It switches a motor's -SurfaceInput from NoInput, |
| Constant and Sin to show how each work using -ParamA and -ParamB properties.Motor Control-- Paste this into a Script inside a part with a Motor SurfaceType |
| local partMotor = script.Parent |
| -- Place a brick called "MovingPart" so it is touching the Motor surface |
|
|
| -- For this example, we use TopSurface, TopSurfaceInput, TopParamA and TopParamB |
| -- However, this will work for all faces (NormalId): Top, Bottom, Left, Right, Front and Back |
|
|
| -- A function to quickly set all surface properties at once |
| local function setFaceSurfaceInputParams(normalId, surfaceType, inputType, paramA, paramB) |
| local surfaceName = normalId.Name -- e.g. "Top", "Bottom", etc |
|
|
| -- Syntax Note: in Lua, part.Something is the same as part["Something"] |
| -- The difference is that the latter allows us to use a string ("Something"), while |
| -- the former requires use of an identifier (.Something). Below, we build of each the surface |
| -- properties below by concatenating the surface name with the property postfix. |
|
|
| -- Set "___Surface", eg "TopSurface" |
| partMotor[surfaceName .. "Surface"] = surfaceType |
| -- Set "___SurfaceInput", eg "TopSurfaceInput" |
| partMotor[surfaceName .. "SurfaceInput"] = inputType |
| -- Set "___ParamA", eg "TopParamA" |
| partMotor[surfaceName .. "ParamA"] = paramA |
| -- Set "___ParamB", eg "TopParamB" |
| partMotor[surfaceName .. "ParamB"] = paramB |
| end |
|
|
| local normalId = Enum.NormalId.Top |
|
|
| while true do |
| -- Set to NoInput, where the motor will not operate at all |
| setFaceSurfaceInputParams(normalId, Enum.SurfaceType.Motor, Enum.InputType.NoInput, 0, 0) |
| task.wait(1) |
| -- Set to Constant, where motor rotational velocity = paramB |
| setFaceSurfaceInputParams(normalId, Enum.SurfaceType.Motor, Enum.InputType.Constant, 0, 0.25) |
| task.wait(2) |
| -- Set to Sin, where motor rotational velocity = paramA * math.sin(time * paramB) |
| -- Since we're using pi (~3.14), the frequency of rotation is 1 second (per definition of sine function) |
| setFaceSurfaceInputParams(normalId, Enum.SurfaceType.Motor, Enum.InputType.Sin, 0.25, math.pi) |
| task.wait(3) |
| endRightSurfaceSurfaceTypeRead ParallelThe RightSurface property determines the type of surface used for the +X |
| direction of a part. When two parts' faces are placed next to each other, |
| they may create a joint between them. If set to Motor, the |
| BasePart.RightSurfaceInput determines how a motor joint should |
| behave. |
| Most SurfaceTypes render a texture on the part face if the |
| BasePart.Material is set to Plastic. Some SurfaceTypes including |
| Hinge, Motor, and SteppingMotor will render a 3D adornment instead. If |
| this property is selected in the Properties window, it will be highlighted |
| in the game world similar to that of a SurfaceSelection.Code SamplesThis code sample shows what each SurfaceType looks like on a part. In |
| addition, it creates a BillboardGui label on the part with a TextLabel that |
| reflects the name of the current SurfaceType.Show All SurfaceTypeslocal demoPart = script.Parent |
|
|
| -- Create a billboard gui to display what the current surface type is |
| local billboard = Instance.new("BillboardGui") |
| billboard.AlwaysOnTop = true |
| billboard.Size = UDim2.new(0, 200, 0, 50) |
| billboard.Adornee = demoPart |
| local textLabel = Instance.new("TextLabel") |
| textLabel.Size = UDim2.new(0, 200, 0, 50) |
| textLabel.BackgroundTransparency = 1 |
| textLabel.TextStrokeTransparency = 0 |
| textLabel.TextColor3 = Color3.new(1, 1, 1) -- White |
| textLabel.Parent = billboard |
| billboard.Parent = demoPart |
|
|
| local function setAllSurfaces(part, surfaceType) |
| part.TopSurface = surfaceType |
| part.BottomSurface = surfaceType |
| part.LeftSurface = surfaceType |
| part.RightSurface = surfaceType |
| part.FrontSurface = surfaceType |
| part.BackSurface = surfaceType |
| end |
|
|
| while true do |
| -- Iterate through the different SurfaceTypes |
| for _, enum in pairs(Enum.SurfaceType:GetEnumItems()) do |
| textLabel.Text = enum.Name |
| setAllSurfaces(demoPart, enum) |
| task.wait(1) |
| end |
| endRightSurfaceInputInputTypeHiddenDEPRECATEDRead ParallelThe RightSurfaceInput property determines the kind of input provided to a |
|
|
| For Sin, the motor rotates at a velocity equal to |
| ParamA * math.sin(workspace.DistributedGameTime * ParamB). See |
| Workspace.DistributedGameTime. |
| Code SamplesThis code sample demonstrates how surface properties can be set using only a |
| NormalId (Top, Front, etc). It switches a motor's -SurfaceInput from NoInput, |
| Constant and Sin to show how each work using -ParamA and -ParamB properties.Motor Control-- Paste this into a Script inside a part with a Motor SurfaceType |
| local partMotor = script.Parent |
| -- Place a brick called "MovingPart" so it is touching the Motor surface |
|
|
| -- For this example, we use TopSurface, TopSurfaceInput, TopParamA and TopParamB |
| -- However, this will work for all faces (NormalId): Top, Bottom, Left, Right, Front and Back |
|
|
| -- A function to quickly set all surface properties at once |
| local function setFaceSurfaceInputParams(normalId, surfaceType, inputType, paramA, paramB) |
| local surfaceName = normalId.Name -- e.g. "Top", "Bottom", etc |
|
|
| -- Syntax Note: in Lua, part.Something is the same as part["Something"] |
| -- The difference is that the latter allows us to use a string ("Something"), while |
| -- the former requires use of an identifier (.Something). Below, we build of each the surface |
| -- properties below by concatenating the surface name with the property postfix. |
|
|
| -- Set "___Surface", eg "TopSurface" |
| partMotor[surfaceName .. "Surface"] = surfaceType |
| -- Set "___SurfaceInput", eg "TopSurfaceInput" |
| partMotor[surfaceName .. "SurfaceInput"] = inputType |
| -- Set "___ParamA", eg "TopParamA" |
| partMotor[surfaceName .. "ParamA"] = paramA |
| -- Set "___ParamB", eg "TopParamB" |
| partMotor[surfaceName .. "ParamB"] = paramB |
| end |
|
|
| local normalId = Enum.NormalId.Top |
|
|
| while true do |
| -- Set to NoInput, where the motor will not operate at all |
| setFaceSurfaceInputParams(normalId, Enum.SurfaceType.Motor, Enum.InputType.NoInput, 0, 0) |
| task.wait(1) |
| -- Set to Constant, where motor rotational velocity = paramB |
| setFaceSurfaceInputParams(normalId, Enum.SurfaceType.Motor, Enum.InputType.Constant, 0, 0.25) |
| task.wait(2) |
| -- Set to Sin, where motor rotational velocity = paramA * math.sin(time * paramB) |
| -- Since we're using pi (~3.14), the frequency of rotation is 1 second (per definition of sine function) |
| setFaceSurfaceInputParams(normalId, Enum.SurfaceType.Motor, Enum.InputType.Sin, 0.25, math.pi) |
| task.wait(3) |
| endRootPrioritynumberRead ParallelThis property is an integer between -127 and 127 that takes precedence |
| over all other rules for root part sort. When considering multiple parts |
| that are not Anchored and which share the same |
| Massless value, a part with a higher |
| RootPriority will take priority over those with lower |
| RootPriority. |
| You can use this property to control which part of an assembly is the root |
| part and keep the root part stable if size changes. |
| See also Understanding Assemblies, an |
| article documenting what root parts are and how to use them.RotVelocityVector3HiddenDEPRECATEDRead ParallelDEPRECATEDThis property is deprecated. Use AssemblyAngularVelocity instead.The RotVelocity of a part describes how its |
| BasePart.Orientation is presently changing. In other words, this |
| property describes how the fast part is rotating. The part only rotates if |
| it is not anchored. |
| The unit of this property is radians per second. |
| Using this in conjunction with AlignOrientation allows for aligned |
| parts to have matching RotVelocity and Orientation values.Code SamplesThe script below creates a new BasePart|part and sets its |
| Part.RotVelocity to Vector3.new(0, 10, 0) every |
| RunService.RenderStepped so that the part rotates in a circular |
| motion.Rotating a Part with RotVelocitylocal RunService = game:GetService("RunService") |
|
|
| local part = Instance.new("Part") |
| part.Name = "RotatingPart" |
| part.Position = Vector3.new(0, 1, 0) |
| part.Parent = workspace |
|
|
| local function renderStepped() |
| part.RotVelocity = Vector3.new(0, 10, 0) |
| end |
|
|
| RunService.RenderStepped:Connect(renderStepped)RotationVector3Not ReplicatedRead ParallelThe rotation of the part in degrees for the three axes. |
| When setting this property any Welds or |
| Motor6Ds connected to this part will have the matching |
| C0 or C1 property |
| updated and to allow the part to move relative to any other parts it is |
| joined to. |
| WeldConstraints will also be temporarily disabled and re-enabled during |
| the move.SizeVector3Not ReplicatedRead ParallelA part's Size property determines its visual |
| dimensions, while ExtentsSize represents the |
| actual size used by the physics engine, for example in |
| collision detection. The individual |
| dimensions (length, width, height) can be as low as 0.001 and as high |
| as 2048. Size dimensions below 0.05 will be visually represented as if |
| the part's dimensions are 0.05. |
| The size of the part determines its mass which is given by |
| BasePart:GetMass(). A part's Size is used by |
| a variety of other objects: |
|
|
| ParticleEmitter to determine the area from which particles are |
| spawned. |
| BlockMesh to partially determine the rendered rectangular prism. |
| SpecialMesh for certain MeshTypes, |
| to determine the size of the rendered mesh. |
| SurfaceLight to determine the space to illuminate. |
| Code SamplesThis code sample constructs a pyramid by stacking parts that get progressively |
| smaller. It also colors the parts so they blend between a start color and end |
| color.Pyramid Builderlocal TOWER_BASE_SIZE = 30 |
|
|
| local position = Vector3.new(50, 50, 50) |
|
|
| local hue = math.random() |
| local color0 = Color3.fromHSV(hue, 1, 1) |
| local color1 = Color3.fromHSV((hue + 0.35) % 1, 1, 1) |
|
|
| local model = Instance.new("Model") |
| model.Name = "Tower" |
|
|
| for i = TOWER_BASE_SIZE, 1, -2 do |
| local part = Instance.new("Part") |
| part.Size = Vector3.new(i, 2, i) |
| part.Position = position |
| part.Anchored = true |
| part.Parent = model |
| -- Tween from color0 and color1 |
| local perc = i / TOWER_BASE_SIZE |
| part.Color = Color3.new( |
| color0.R * perc + color1.R * (1 - perc), |
| color0.G * perc + color1.G * (1 - perc), |
| color0.B * perc + color1.B * (1 - perc) |
| ) |
|
|
| position = position + Vector3.new(0, part.Size.Y, 0) |
| end |
| model.Parent = workspaceSpecificGravitynumberRead OnlyNot ReplicatedDEPRECATEDRead ParallelDEPRECATEDThis item is deprecated. See BasePart.CustomPhysicalProperties to |
| see how to configure the physical properties of BaseParts. Do not use it |
| for new work.The ratio of the part's density to the density of water determined by the |
| BasePart.Material. Effects the part's behavior when in a water |
| terrain cell. Essentially, SpecificGravity refers to how many times more |
| dense a part is than water. |
| MaterialSpecificGravityPlastic0.7Wood0.35Slate2.7Concrete2.4CorrodedMetal7.85DiamondMetal7.85Foil7.6Grass0.9Ice0.91Marble2.56Granite2.7Brick1.92Pebble2.4Sand1.6Fabric0.7SmoothPlastic0.7Metal7.85WoodPlanks0.35Cobblestone2.7TopParamAnumberHiddenDEPRECATEDRead ParallelThe TopParamA property is relevant when a part's |
| BasePart.TopSurface is set to Motor or SteppingMotor and |
| BasePart.TopSurfaceInput is set to Sin. It determines the |
| amplitude of the motor's rotational velocity, using the following |
| formula: |
| MotorVelocity = ParamA * math.sin(workspace.DistributedGameTime * ParamB) |
| In no other cases is this property used.Code SamplesThis code sample demonstrates how surface properties can be set using only a |
| NormalId (Top, Front, etc). It switches a motor's -SurfaceInput from NoInput, |
| Constant and Sin to show how each work using -ParamA and -ParamB properties.Motor Control-- Paste this into a Script inside a part with a Motor SurfaceType |
| local partMotor = script.Parent |
| -- Place a brick called "MovingPart" so it is touching the Motor surface |
|
|
| -- For this example, we use TopSurface, TopSurfaceInput, TopParamA and TopParamB |
| -- However, this will work for all faces (NormalId): Top, Bottom, Left, Right, Front and Back |
|
|
| -- A function to quickly set all surface properties at once |
| local function setFaceSurfaceInputParams(normalId, surfaceType, inputType, paramA, paramB) |
| local surfaceName = normalId.Name -- e.g. "Top", "Bottom", etc |
|
|
| -- Syntax Note: in Lua, part.Something is the same as part["Something"] |
| -- The difference is that the latter allows us to use a string ("Something"), while |
| -- the former requires use of an identifier (.Something). Below, we build of each the surface |
| -- properties below by concatenating the surface name with the property postfix. |
|
|
| -- Set "___Surface", eg "TopSurface" |
| partMotor[surfaceName .. "Surface"] = surfaceType |
| -- Set "___SurfaceInput", eg "TopSurfaceInput" |
| partMotor[surfaceName .. "SurfaceInput"] = inputType |
| -- Set "___ParamA", eg "TopParamA" |
| partMotor[surfaceName .. "ParamA"] = paramA |
| -- Set "___ParamB", eg "TopParamB" |
| partMotor[surfaceName .. "ParamB"] = paramB |
| end |
|
|
| local normalId = Enum.NormalId.Top |
|
|
| while true do |
| -- Set to NoInput, where the motor will not operate at all |
| setFaceSurfaceInputParams(normalId, Enum.SurfaceType.Motor, Enum.InputType.NoInput, 0, 0) |
| task.wait(1) |
| -- Set to Constant, where motor rotational velocity = paramB |
| setFaceSurfaceInputParams(normalId, Enum.SurfaceType.Motor, Enum.InputType.Constant, 0, 0.25) |
| task.wait(2) |
| -- Set to Sin, where motor rotational velocity = paramA * math.sin(time * paramB) |
| -- Since we're using pi (~3.14), the frequency of rotation is 1 second (per definition of sine function) |
| setFaceSurfaceInputParams(normalId, Enum.SurfaceType.Motor, Enum.InputType.Sin, 0.25, math.pi) |
| task.wait(3) |
| endTopParamBnumberHiddenDEPRECATEDRead ParallelThe TopParamB property is relevant when a part's |
| BasePart.TopSurface is set to Motor or SteppingMotor and |
| BasePart.TopSurfaceInput is set to Constant or Sin. For Constant, |
| it determines the constant rotational velocity of the motor. For Sin, it |
| determines the frequency of the motor's rotational velocity, using the |
| following formula: |
| MotorVelocity = ParamB * math.sin(workspace.DistributedGameTime * ParamB) |
| In no other cases is this property used.Code SamplesThis code sample demonstrates how surface properties can be set using only a |
| NormalId (Top, Front, etc). It switches a motor's -SurfaceInput from NoInput, |
| Constant and Sin to show how each work using -ParamA and -ParamB properties.Motor Control-- Paste this into a Script inside a part with a Motor SurfaceType |
| local partMotor = script.Parent |
| -- Place a brick called "MovingPart" so it is touching the Motor surface |
|
|
| -- For this example, we use TopSurface, TopSurfaceInput, TopParamA and TopParamB |
| -- However, this will work for all faces (NormalId): Top, Bottom, Left, Right, Front and Back |
|
|
| -- A function to quickly set all surface properties at once |
| local function setFaceSurfaceInputParams(normalId, surfaceType, inputType, paramA, paramB) |
| local surfaceName = normalId.Name -- e.g. "Top", "Bottom", etc |
|
|
| -- Syntax Note: in Lua, part.Something is the same as part["Something"] |
| -- The difference is that the latter allows us to use a string ("Something"), while |
| -- the former requires use of an identifier (.Something). Below, we build of each the surface |
| -- properties below by concatenating the surface name with the property postfix. |
|
|
| -- Set "___Surface", eg "TopSurface" |
| partMotor[surfaceName .. "Surface"] = surfaceType |
| -- Set "___SurfaceInput", eg "TopSurfaceInput" |
| partMotor[surfaceName .. "SurfaceInput"] = inputType |
| -- Set "___ParamA", eg "TopParamA" |
| partMotor[surfaceName .. "ParamA"] = paramA |
| -- Set "___ParamB", eg "TopParamB" |
| partMotor[surfaceName .. "ParamB"] = paramB |
| end |
|
|
| local normalId = Enum.NormalId.Top |
|
|
| while true do |
| -- Set to NoInput, where the motor will not operate at all |
| setFaceSurfaceInputParams(normalId, Enum.SurfaceType.Motor, Enum.InputType.NoInput, 0, 0) |
| task.wait(1) |
| -- Set to Constant, where motor rotational velocity = paramB |
| setFaceSurfaceInputParams(normalId, Enum.SurfaceType.Motor, Enum.InputType.Constant, 0, 0.25) |
| task.wait(2) |
| -- Set to Sin, where motor rotational velocity = paramA * math.sin(time * paramB) |
| -- Since we're using pi (~3.14), the frequency of rotation is 1 second (per definition of sine function) |
| setFaceSurfaceInputParams(normalId, Enum.SurfaceType.Motor, Enum.InputType.Sin, 0.25, math.pi) |
| task.wait(3) |
| endTopSurfaceSurfaceTypeRead ParallelThe TopSurface property determines the type of surface used for the +Y |
| direction of a part. When two parts' faces are placed next to each other, |
| they may create a joint between them. If set to Motor, the |
| BasePart.TopSurfaceInput determines how a motor joint should |
| behave. |
| Most SurfaceTypes render a texture on the part face if the |
| BasePart.Material is set to Plastic. Some SurfaceTypes - Hinge, |
| Motor and SteppingMotor - will render a 3D adornment instead. If this |
| property is selected in the Properties window, it will be highlighted in |
| the game world similar to that of a SurfaceSelection.Code SamplesThis code sample shows what each SurfaceType looks like on a part. In |
| addition, it creates a BillboardGui label on the part with a TextLabel that |
| reflects the name of the current SurfaceType.Show All SurfaceTypeslocal demoPart = script.Parent |
|
|
| -- Create a billboard gui to display what the current surface type is |
| local billboard = Instance.new("BillboardGui") |
| billboard.AlwaysOnTop = true |
| billboard.Size = UDim2.new(0, 200, 0, 50) |
| billboard.Adornee = demoPart |
| local textLabel = Instance.new("TextLabel") |
| textLabel.Size = UDim2.new(0, 200, 0, 50) |
| textLabel.BackgroundTransparency = 1 |
| textLabel.TextStrokeTransparency = 0 |
| textLabel.TextColor3 = Color3.new(1, 1, 1) -- White |
| textLabel.Parent = billboard |
| billboard.Parent = demoPart |
|
|
| local function setAllSurfaces(part, surfaceType) |
| part.TopSurface = surfaceType |
| part.BottomSurface = surfaceType |
| part.LeftSurface = surfaceType |
| part.RightSurface = surfaceType |
| part.FrontSurface = surfaceType |
| part.BackSurface = surfaceType |
| end |
|
|
| while true do |
| -- Iterate through the different SurfaceTypes |
| for _, enum in pairs(Enum.SurfaceType:GetEnumItems()) do |
| textLabel.Text = enum.Name |
| setAllSurfaces(demoPart, enum) |
| task.wait(1) |
| end |
| endTopSurfaceInputInputTypeHiddenDEPRECATEDRead ParallelThe TopSurfaceInput property determines the kind of input provided to a |
| part's BasePart.TopSurface. This is only relevant for Motor or |
| SteppingMotor SurfaceTypes. This property determines how |
| BasePart.TopParamA and BasePart.TopParamB are used. For |
| brevity, these properties will be referred to as ParamA and ParamB, |
| respectively. |
|
|
| By default, this is set to NoInput. This stops the motor altogether, |
| For Constant, the motor rotates at a constant velocity equal to |
| ParamB. |
| For Sin, the motor rotates at a velocity equal to |
| ParamA * math.sin(workspace.DistributedGameTime * ParamB). See |
| Workspace.DistributedGameTime. |
| Code SamplesThis code sample demonstrates how surface properties can be set using only a |
| NormalId (Top, Front, etc). It switches a motor's -SurfaceInput from NoInput, |
| Constant and Sin to show how each work using -ParamA and -ParamB properties.Motor Control-- Paste this into a Script inside a part with a Motor SurfaceType |
| local partMotor = script.Parent |
| -- Place a brick called "MovingPart" so it is touching the Motor surface |
|
|
| -- For this example, we use TopSurface, TopSurfaceInput, TopParamA and TopParamB |
| -- However, this will work for all faces (NormalId): Top, Bottom, Left, Right, Front and Back |
|
|
| -- A function to quickly set all surface properties at once |
| local function setFaceSurfaceInputParams(normalId, surfaceType, inputType, paramA, paramB) |
| local surfaceName = normalId.Name -- e.g. "Top", "Bottom", etc |
|
|
| -- Syntax Note: in Lua, part.Something is the same as part["Something"] |
| -- The difference is that the latter allows us to use a string ("Something"), while |
| -- the former requires use of an identifier (.Something). Below, we build of each the surface |
| -- properties below by concatenating the surface name with the property postfix. |
|
|
| -- Set "___Surface", eg "TopSurface" |
| partMotor[surfaceName .. "Surface"] = surfaceType |
| -- Set "___SurfaceInput", eg "TopSurfaceInput" |
| partMotor[surfaceName .. "SurfaceInput"] = inputType |
| -- Set "___ParamA", eg "TopParamA" |
| partMotor[surfaceName .. "ParamA"] = paramA |
| -- Set "___ParamB", eg "TopParamB" |
| partMotor[surfaceName .. "ParamB"] = paramB |
| end |
|
|
| local normalId = Enum.NormalId.Top |
|
|
| while true do |
| -- Set to NoInput, where the motor will not operate at all |
| setFaceSurfaceInputParams(normalId, Enum.SurfaceType.Motor, Enum.InputType.NoInput, 0, 0) |
| task.wait(1) |
| -- Set to Constant, where motor rotational velocity = paramB |
| setFaceSurfaceInputParams(normalId, Enum.SurfaceType.Motor, Enum.InputType.Constant, 0, 0.25) |
| task.wait(2) |
| -- Set to Sin, where motor rotational velocity = paramA * math.sin(time * paramB) |
| -- Since we're using pi (~3.14), the frequency of rotation is 1 second (per definition of sine function) |
| setFaceSurfaceInputParams(normalId, Enum.SurfaceType.Motor, Enum.InputType.Sin, 0.25, math.pi) |
| task.wait(3) |
| endTransparencynumberRead ParallelThe Transparency property controls the visibility of a part on a scale of |
| 0 to 1, where 0 is completely visible (opaque), and a value of 1 is |
| completely invisible (not rendered at all). |
| BasePart.Reflectance can reduce the overall transparency of a |
| brick if set to a value close to 1. |
| While fully transparent parts are not rendered at all, partially |
| transparent objects have some significant rendering costs. Having many |
| translucent parts may slow down the game's performance. |
| When transparent parts overlap, render order can act unpredictable - try |
| to keep semi-transparent parts from overlapping to avoid this. |
| The BasePart.LocalTransparencyModifier is a multiplier to |
| Transparency that is only visible to the local client.Code SamplesThis code sample shows how a part can fade away when touched by a Humanoid |
| then reappear a moment after to create a passable door.Fade Door-- Paste into a Script inside a tall part |
| local part = script.Parent |
|
|
| local OPEN_TIME = 1 |
|
|
| -- Can the door be opened at the moment? |
| local debounce = false |
|
|
| local function open() |
| part.CanCollide = false |
| part.Transparency = 0.7 |
| part.BrickColor = BrickColor.new("Black") |
| end |
|
|
| local function close() |
| part.CanCollide = true |
| part.Transparency = 0 |
| part.BrickColor = BrickColor.new("Bright blue") |
| end |
|
|
| local function onTouch(otherPart) |
| -- If the door was already open, do nothing |
| if debounce then |
| print("D") |
| return |
| end |
|
|
| -- Check if touched by a Humanoid |
| local human = otherPart.Parent:FindFirstChildOfClass("Humanoid") |
| if not human then |
| print("not human") |
| return |
| end |
|
|
| -- Perform the door opening sequence |
| debounce = true |
| open() |
| task.wait(OPEN_TIME) |
| close() |
| debounce = false |
| end |
|
|
| part.Touched:Connect(onTouch) |
| close()This code sample gives the local client X-ray vision using |
| LocalTransparencyModifier. It allows the player to see through all parts in |
| the Workspace, which are found using recursion.X-Ray Visionlocal function makeXRayPart(part) |
| -- LocalTransparencyModifier will make parts see-through but only for the local |
| -- client, and it won't replicate to the server |
| part.LocalTransparencyModifier = 0.5 |
| end |
|
|
| -- This function uses recursion to search for parts in the game |
| local function recurseForParts(object) |
| if object:IsA("BasePart") then |
| makeXRayPart(object) |
| end |
|
|
| -- Stop if this object has a Humanoid - we don't want to see-through players! |
| if object:FindFirstChildOfClass("Humanoid") then |
| return |
| end |
|
|
| -- Check the object's children for more parts |
| for _, child in pairs(object:GetChildren()) do |
| recurseForParts(child) |
| end |
| end |
|
|
| recurseForParts(workspace)VelocityVector3HiddenDEPRECATEDRead ParallelDEPRECATEDThis property is deprecated. Use AssemblyLinearVelocity instead.The Velocity of a part describes how its BasePart.Position is |
| presently changing. The unit of this property is studs per second. For |
| reference, the default Roblox character moves at 16 studs per second via |
| Humanoid.WalkSpeed. The acceleration due to gravity is found in |
| Workspace.Gravity (by default, -196.2 studs per second per |
| second). |
| Setting the Velocity of an part that is BasePart.Anchored will |
| cause it to act like a conveyor belt. Any object that touches the part |
| will begin to move in accordance with the Velocity. |
| Some BodyMover objects will apply forces and thus change the |
| Velocity of a part over time. The simplest of these is a BodyForce |
| which can be used to counteract the acceleration due to gravity on a |
| single part (set the +Y axis of the BodyForce.Force to the product |
| of the mass (BasePart:GetMass()) and the gravity constant).Code SamplesThis code sample fires a part from one position toward another. It calculates |
| the velocity needed to reach the destination in time, and applies an |
| anti-gravity effect using a BodyForce. In addition, it adds a Trail to better |
| visualize the path of the projectile as it arcs through the air.Projectile Firing-- Put this Script in a Part, preferably bullet-shaped :) |
| local part = script.Parent |
| part.Shape = Enum.PartType.Ball |
| part.Size = Vector3.new(2, 2, 2) |
| part.BrickColor = BrickColor.new("Really black") |
| part.CanCollide = false |
|
|
| local MY_START_POINT = Vector3.new(0, 50, 0) |
| local MY_TARGET_POINT = Vector3.new(50, 100, 0) |
| local TRAVEL_TIME = 1 |
| local ANTI_GRAVITY = 0.5 |
|
|
| -- Anti-gravity effect: add a BodyForce to counter gravity |
| local bf = Instance.new("BodyForce") |
| bf.Force = Vector3.new(0, workspace.Gravity * part:GetMass() * ANTI_GRAVITY, 0) |
| bf.Parent = part |
|
|
| local a0 = Instance.new("Attachment") |
| a0.Position = Vector3.new(1, 0, 0) |
| a0.Parent = part |
|
|
| local a1 = Instance.new("Attachment") |
| a1.Position = Vector3.new(-1, 0, 0) |
| a1.Parent = part |
|
|
| local trail = Instance.new("Trail") |
| trail.Parent = part |
| trail.Attachment0 = a0 |
| trail.Attachment1 = a1 |
| trail.FaceCamera = true |
| trail.Transparency = NumberSequence.new({ |
| NumberSequenceKeypoint.new(0, 0), |
| NumberSequenceKeypoint.new(1, 1), |
| }) |
| trail.Lifetime = 0.35 |
|
|
| local function fire(startPoint, targetPoint) |
| -- Calculate how far we have to travel |
| local distance = (targetPoint - startPoint).magnitude |
| local speed = distance / TRAVEL_TIME |
| part.CFrame = CFrame.new(startPoint, targetPoint) |
| -- Shoot the part |
| part.Velocity = part.CFrame.LookVector * speed |
| end |
|
|
| while true do |
| fire(MY_START_POINT, MY_TARGET_POINT) |
| task.wait(TRAVEL_TIME) |
| endbrickColorBrickColorNot ReplicatedDEPRECATEDRead ParallelDEPRECATEDThis deprecated property is an old Camel Case variant of the Pascal Case |
| BasePart.BrickColor, which should be used instead.Properties inherited from PVInstanceOriginCFrameNot ReplicatedNot ScriptableRead ParallelPivot OffsetCFrameNot ReplicatedNot ScriptableRead ParallelProperties inherited from InstanceArchivablebooleanRead ParallelThis property determines whether an object should be |
| included when the game is published or saved, or when |
| Instance:Clone() is called on one of the object's ancestors. |
| Calling Clone directly on an object will return nil if the cloned object |
| is not archivable. Copying an object in Studio (using the 'Duplicate' or |
| 'Copy' options) will ignore the Archivable property and set Archivable to |
| true for the copy. |
| local part = Instance.new("Part") |
| print(part:Clone()) --> Part |
| part.Archivable = false |
| print(part:Clone()) --> nilClassNamestringRead OnlyNot ReplicatedRead ParallelA read-only string representing the class this Instance belongs |
| to. |
| This property can be used with various other functions of Instance that |
| are used to identify objects by type, such as Instance:IsA() or |
| Instance:FindFirstChildOfClass(). |
| Note this property is read only and cannot be altered by scripts. |
| Developers wishing to change an Instance's class will instead have |
| to create a new Instance. |
| Unlike Instance:IsA(), ClassName can be used to check if an object |
| belongs to a specific class ignoring class inheritance. For example: |
| for _, child in ipairs(game.Workspace:GetChildren()) do |
| if child.ClassName == "Part" then |
| print("Found a Part") |
| -- will find Parts in model, but NOT TrussParts, WedgeParts, etc |
| end |
| endNamestringRead ParallelA non-unique identifier of the Instance. |
| This property is an identifier that describes an object. Names are not |
| necessarily unique identifiers however; multiple children of an object may |
| share the same name. Names are used to keep the object hierarchy |
| organized, along with allowing scripts to access specific objects. |
| The name of an object is often used to access the object through the data |
| model hierarchy using the following methods: |
| local baseplate = workspace.Baseplate |
| local baseplate = workspace["Baseplate"] |
| local baseplate = workspace:FindFirstChild("BasePlate") |
| In order to make an object accessible using the dot operator, an object's |
| Name must follow a certain syntax. The objects name must start with an |
| underscore or letter. The rest of the name can only contain letters, |
| numbers, or underscores (no other special characters). If an objects name |
| does not follow this syntax it will not be accessible using the dot |
| operator and Lua will not interpret its name as an identifier. |
| If more than one object with the same name are siblings then any attempt |
| to index an object by that name will return the only one of the objects |
| found similar to Instance:FindFirstChild(), but not always the |
| desired object. If a specific object needs to be accessed through code, it |
| is recommended to give it a unique name, or guarantee that none of its |
| siblings share the same name as it. |
| Note, a full name showing the instance's hierarchy can be obtained using |
| Instance:GetFullName().ParentInstanceNot ReplicatedRead ParallelThe Parent property determines the hierarchical parent of the |
| Instance. The following terminology is commonly used when talking |
| about how this property is set: |
|
|
| An object is a child (parented to) another object when its |
| Parent is set to that object. |
| The descendants of an Instance are the children of that |
| object, plus the descendants of the children as well. |
| The ancestors of an Instance are all the objects that the |
| Instance is a descendant of. |
|
|
| It is from this property that many other API members get their name, such |
| as GetChildren and |
| FindFirstChild. |
| The Remove function sets this property to nil. |
| Calling Destroy will set the Parent of an |
| Instance and all of its descendants to nil, and also lock |
| the Parent property. An error is raised when setting the Parent of a |
| destroyed object. |
| This property is also used to manage whether an object exists in the game |
| or needs removed. As long as an objects parent is in the |
| DataModel, is stored in a variable, or is referenced by another |
| objects property, then the object remains in the game. Otherwise, the |
| object will automatically be removed. The top level DataModel |
| object (the one referred to as the game by scripts) has no parent, but |
| always has a reference held to it by the game engine, and exists for the |
| duration of a session. |
| Newly created objects using Instance.new() will not have a |
| parent, and usually will not be visible or function until one is set. The |
| most elementary creation of an object has two steps: creating the object, |
| then setting its parent. |
| -- Create a part and parent it to the workspace |
| local part = Instance.new("Part") |
| part.Parent = workspace |
| -- Instance new can also take Parent as a second parameter |
| Instance.new("NumberValue", workspace) |
| Object Replication |
| An object created by server will not replicate to clients until it is |
| parented to some object that is replicated. When creating an object then |
| setting many properties, it's recommended to set Parent last. This |
| ensures the object replicates once, instead of replicating many property |
| changes. |
| local part = Instance.new("Part") -- Avoid using the second parameter here |
| part.Anchored = true |
| part.BrickColor = BrickColor.new("Really red") |
| -- Potentially many other property changes could go here here... |
| -- Always set parent last! |
| part.Parent = workspace |
| However, if you were parenting your parts to a Model whose parent |
| hasn't been set yet, then setting the parent first would not matter as the |
| model would not have replicated yet.RobloxLockedbooleanHiddenPlugin SecurityRead ParallelThis property used to protect objects in the CoreGui service from |
| being altered by users in an unauthorized manner. It has been deprecated |
| and does not do anything.archivablebooleanHiddenNot ReplicatedDEPRECATEDRead ParallelDEPRECATEDThis deprecated property is a variant of Instance.Archivable which |
| should be used instead.classNamestringRead OnlyNot ReplicatedDEPRECATEDRead ParallelDEPRECATEDThis deprecated property is a variant of Instance.ClassName which |
| should be used instead.MethodsMethods inherited from BasePartApplyAngularImpulsevoidApplies an instant angular force impulse to this part's |
| assembly, causing the assembly to spin. |
| The resulting angular velocity from the impulse relies on the assembly's |
| mass. So a higher impulse is required to |
| move more massive assemblies. Impulses are useful for cases where you want |
| a force applied instantly, such as an explosion or collision. |
| If the part is owned by the server, this function must be called on a |
| server Script. If the part is owned by a client, this function can |
| be called on a LocalScript or server Script.Parametersimpulse: Vector3A force vector to be applied to the assembly as an impulse.ReturnsvoidApplyImpulsevoidThis function applies an instant force impulse to this |
| part's assembly. |
| The force is applied at the assembly's |
| center of mass, so the resulting |
| movement will only be linear. |
| The resulting velocity from the impulse relies on the assembly's |
| mass. So a higher impulse is required to |
| move more massive assemblies. Impulses are useful for cases where you want |
| a force applied instantly, such as an explosion or collision. |
| If the part is owned by the server, this function must be called on a |
| server Script. If the part is owned by a client, this function can |
| be called on a LocalScript or server Script.Parametersimpulse: Vector3A force vector to be applied to the assembly as an impulse.ReturnsvoidApplyImpulseAtPositionvoidThis function applies an instant force impulse to this |
| part's assembly, at the specified position in world |
| space. |
| If the position is not at the assembly's |
| center of mass, the impulse will |
| cause a positional and rotational movement. |
| The resulting velocity from the impulse relies on the assembly's |
| mass. So a higher impulse is required to |
| move more massive assemblies. Impulses are useful for cases where |
| developers want a force applied instantly, such as an explosion or |
| collision. |
| If the part is owned by the server, this function must be called on a |
| server Script. If the part is owned by a client, this function can |
| be called on a LocalScript or server Script.Parametersimpulse: Vector3A force vector to be applied to the assembly as an impulse.position: Vector3The position, in world space, to apply the impulse.ReturnsvoidBreakJointsvoidDEPRECATEDBreaks any surface connection with any adjacent part, including |
| Weld and other JointInstance.ReturnsvoidCanCollideWithbooleanWrite ParallelReturns whether the parts can collide with each other or not. This |
| function takes into account the collision groups of the two parts. This |
| function will error if the specified part is not a BasePart.Parameterspart: BasePartThe specified part being checked for collidability.ReturnsbooleanWhether the parts can collide with each other.CanSetNetworkOwnershipTupleThe CanSetNetworkOwnership function checks whether you can set a |
| part's network ownership. |
| The function's return value verifies whether or not you can call |
| BasePart:SetNetworkOwner() or |
| BasePart:SetNetworkOwnershipAuto() without encountering an error. |
| It returns true if you can modify/read the network ownership, or returns |
| false and the reason you can't, as a string.ReturnsTupleWhether you can modify or read the network ownership and the reason.Code SamplesThis example checks whether or not the network ownership of the first |
| BasePart named Part in the Workspace can be set.Check if a Part's Network Ownership Can Be Setlocal part = workspace:FindFirstChild("Part") |
|
|
| if part and part:IsA("BasePart") then |
| local canSet, errorReason = part:CanSetNetworkOwnership() |
| if canSet then |
| print(part:GetFullName() .. "'s Network Ownership can be changed!") |
| else |
| warn("Cannot change the Network Ownership of " .. part:GetFullName() .. " because: " .. errorReason) |
| end |
| endGetClosestPointOnSurfaceVector3Parametersposition: Vector3ReturnsVector3GetConnectedPartsObjectsWrite ParallelReturns a table of parts connected to the object by any kind of rigid |
| joint. |
| If recursive is true this function will return all of the parts in the |
| assembly rigidly connected to the BasePart. |
| Rigid Joints |
| When a joint connects two parts together (Part0 → Part1), a joint is |
| rigid if the physics of Part1 are completely locked down by Part0. |
| This only applies to the following joint types: |
|
|
| Weld |
| Snap |
| ManualWeld |
| Motor |
| Motor6D |
| WeldConstraint |
| Parametersrecursive: booleanA table of parts connected to the object by any kind of |
| joint.Default Value: falseReturnsObjectsGetJointsObjectsWrite ParallelReturn all Joints or Constraints that is connected to this Part.ReturnsObjectsAn array of all Joints or Constraints connected to the Part.GetMassnumberWrite ParallelGetMass returns the value of the read-only Mass |
| property. |
| This function predates the Mass property. It remains supported for |
| backward-compatibility; you should use the Mass property directly.ReturnsnumberThe part's mass.Code SamplesThis example creates a new part, myPart, in the game's Workspace, with |
| dimensions 4x6x4 studs. The part is also anchored. |
| Then, myMass is set to equal the mass of the new part. The mass of the part is |
| printed at the end of the print statement: |
|
|
| My part's mass is ... |
| Finding a Part's Masslocal myPart = Instance.new("Part") |
| myPart.Size = Vector3.new(4, 6, 4) |
| myPart.Anchored = true |
| myPart.Parent = workspace |
|
|
| local myMass = myPart:GetMass() |
|
|
| print("My part's mass is " .. myMass)GetNetworkOwnerInstanceWrite ParallelReturns the current player who is the network owner of this part, or nil |
| in case of the server.ReturnsInstanceThe current player who is the network owner of this part, or nil in |
| case of the server.GetNetworkOwnershipAutobooleanWrite ParallelReturns true if the game engine automatically decides the network owner |
| for this part.ReturnsbooleanWhether the game engine automatically decides the network owner for |
| this part.GetNoCollisionConstraintsObjectsReturnsObjectsGetRenderCFrameCFrameDEPRECATEDDEPRECATEDThis item is been deprecated since interpolation is now applied to the |
| CFrame directly. Do not use it for new work.This function used to be relevant when Roblox's lag-compensating |
| interpolation of parts online was internal. The interpolation is now |
| applied to the CFrame directly.ReturnsCFrameGetRootPartInstanceWrite ParallelReturns the base part of an assembly. When moving an assembly of parts |
| using a CFrame. it is important to move this base part (this |
| will move all other parts connected to it accordingly). |
| More information is available in the |
| Understanding Assemblies article. |
| This function predates the AssemblyRootPart property. It remains |
| supported for backward-compatibility; you should use the |
| AssemblyRootPart property directly.ReturnsInstanceThe base part of an assembly (a collection of parts connected |
| together).GetTouchingPartsObjectsReturns a table of all parts that are physically interacting with this |
| part. If the part itself has CanCollide set to false, then this function |
| returns an empty table unless the part has a |
| TouchInterest object parented to it (meaning |
| something is connected to its Touched event). Parts that are adjacent but |
| not intersecting are not considered touching. This function predates the |
| WorldRoot:GetPartsInPart() function, which provides more |
| flexibility and avoids the special TouchInterest |
| rules described above. Use WorldRoot:GetPartsInPart() instead.ReturnsObjectsA table of all parts that intersect and can collide with this part.GetVelocityAtPositionVector3Write ParallelReturns the linear velocity of the part's assembly at the given position |
| relative to this part. It can be used to identify the linear velocity of |
| parts in an assembly other than the root part. If the assembly has no |
| angular velocity, than the linear velocity will always be the same for |
| every position.Parametersposition: Vector3ReturnsVector3IsGroundedbooleanWrite ParallelReturns true if the object is connected to a part that will hold it in |
| place (eg an BasePart.Anchored part), otherwise returns false. In |
| an assembly that has an BasePart.Anchored part, every other part |
| is grounded.ReturnsbooleanWhether the object is connected to a part that will hold it in place.MakeJointsvoidDEPRECATEDDEPRECATEDSurfaceType based joining is deprecated, do not use MakeJoints for new |
| projects. WeldConstraints and |
| HingeConstraints should be used instead.Creates a joint on any side of the Part that has a |
| SurfaceType that can make a joint it will create a joint with any |
| adjacent parts. |
| Joints will be created between the sides and any planar touching surfaces, |
| depending on the sides' surfaces. |
|
|
| Smooth surfaces will not create joints |
| Glue surfaces will create a Glue joint |
| Weld will create a Weld joint with any surface except for |
| Unjoinable |
| Studs, Inlet, or Universal will each create a Snap joint with |
| either of other the other two surfaces (e.g. Studs with Inlet and |
| Universal) |
| Hinge and Motor surfaces create Rotate and RotateV joint |
| instances |
|
|
| Unlike Model:MakeJoints(), this function requires an array of |
| parts as a parameter. This array is given as follows: |
| part:MakeJoints({part1, part2, part3}) |
| Joints are broken if enough force is applied to them due to an |
| Explosion, unless a ForceField object is parented to the |
| BasePart or ancestor Model. For this reason, they are |
| often used to make simple destructible buildings and other models.ReturnsvoidResizebooleanChanges the size of an object just like using the Studio resize tool.ParametersnormalId: NormalIdThe side to resize.deltaAmount: numberHow much to grow/shrink on the specified side.ReturnsbooleanWhether the part is resized.SetNetworkOwnervoidSets the given player as network owner for this and all connected parts. |
| When playerInstance is nil, the server will be the owner instead of a |
| player.ParametersplayerInstance: PlayerThe player being given network ownership of the part.Default Value: "nil"ReturnsvoidSetNetworkOwnershipAutovoidLets the game engine dynamically decide who will handle the part's physics |
| (one of the clients or the server).ReturnsvoidbreakJointsvoidDEPRECATEDDEPRECATEDThis deprecated function is a variant of BasePart:BreakJoints() |
| which should be used instead.ReturnsvoidgetMassnumberDEPRECATEDDEPRECATEDThis Camel Case property has been deprecated in favor of its Pascal Case |
| variant, BasePart:GetMass().ReturnsnumbermakeJointsvoidDEPRECATEDDEPRECATEDThis deprecated function is a variant of BasePart:MakeJoints() |
| which should be used instead.ReturnsvoidresizebooleanDEPRECATEDDEPRECATEDThis deprecated function is a variant of BasePart:Resize() which |
| should be used instead.ParametersnormalId: NormalIddeltaAmount: numberReturnsbooleanIntersectAsyncInstanceYieldsCreates a new IntersectOperation from the intersecting geometry of |
| the part and the other parts in the given array. Only Parts |
| are supported, not Terrain or MeshParts. Similar |
| to Clone(), the returned object has no set |
| Parent. |
| The following properties from the calling part are applied to the |
| resulting IntersectOperation: |
|
|
| Color, Material, |
| MaterialVariant, |
| Reflectance, |
| Transparency |
| CanCollide |
| Anchored, Density, |
| Elasticity, |
| ElasticityWeight, |
| Friction, |
| FrictionWeight |
|
|
| In the following image comparison, |
| IntersectAsync() is called on the purple |
| block using a table containing the blue block. The resulting |
| IntersectOperation resolves into a shape of the intersecting |
| geometry of both parts. |
|
|
|
|
| Separate parts |
|
|
|
|
|
|
| Resulting IntersectOperation |
|
|
| Notes |
|
|
| The original parts remain intact following a successful intersect |
| operation. In most cases, you should Destroy() |
| all of the original parts and parent the returned |
| IntersectOperation to the same place as the calling |
| BasePart. |
| By default, the face colors of the resulting intersection are borrowed |
| from the Color property of the original parts. To |
| change the entire intersection to a specific color, set its |
| UsePartColor property to true. |
| If an intersect operation would result in a part with more than 20,000 |
| triangles, it will be simplified to 20,000 triangles. |
| Parametersparts: ObjectsThe objects taking part in the intersection.collisionfidelity: CollisionFidelityThe CollisionFidelity value for the resulting |
| IntersectOperation.Default Value: "Default"renderFidelity: RenderFidelityThe RenderFidelity value of the resulting |
| PartOperation.Default Value: "Automatic"ReturnsInstanceResulting IntersectOperation with default name Intersect.SubtractAsyncInstanceYieldsCreates a new UnionOperation from the part, minus the geometry |
| occupied by the parts in the given array. Only Parts are |
| supported, not Terrain or MeshParts. Similar to |
| Clone(), the returned object has no set |
| Parent. |
| Note that the resulting union cannot be empty due to subtractions. If the |
| operation would result in completely empty geometry, it will fail. |
| In the following image comparison, |
| SubtractAsync() is called on the blue |
| cylinder using a table containing the purple block. The resulting |
| UnionOperation resolves into a shape that omits the block's |
| geometry from that of the cylinder. |
|
|
|
|
| Separate parts |
|
|
|
|
|
|
| Resulting UnionOperation |
| Parametersparts: ObjectsThe objects taking part in the subtraction.collisionfidelity: CollisionFidelityThe CollisionFidelity value for the resulting |
| UnionOperation.Default Value: "Default"renderFidelity: RenderFidelityThe RenderFidelity value of the resulting |
| PartOperation.Default Value: "Automatic"ReturnsInstanceResulting UnionOperation with default name Union.Code SamplesThis example demonstrates how to subtract part(s) from another |
| BasePart to form a negated UnionOperation.BasePart:SubtractAsync()local mainPart = workspace.BlueBlock |
| local otherParts = {workspace.PurpleCylinder} |
|
|
| -- Perform subtract operation |
| local success, newSubtract = pcall(function() |
| return mainPart:SubtractAsync(otherParts) |
| end) |
|
|
| -- If operation succeeds, position it at the same location and parent it to the workspace |
| if success and newSubtract then |
| newSubtract.Position = mainPart.Position |
| newSubtract.Parent = workspace |
| end |
|
|
| -- Destroy original parts which remain intact after operation |
| mainPart:Destroy() |
| for i = 1, #otherParts do |
| otherParts[i]:Destroy() |
| endUnionAsyncInstanceYieldsCreates a new UnionOperation from the part, plus the geometry |
| occupied by the parts in the given array. Only Parts are |
| supported, not Terrain or MeshParts. Similar to |
| Clone(), the returned object has no set |
| Parent. |
| The following properties from the calling part are applied to the |
| resulting UnionOperation: |
|
|
| Color, Material, |
| MaterialVariant, |
| Reflectance, |
| Transparency |
| CanCollide |
| Anchored, Density, |
| Elasticity, |
| ElasticityWeight, |
| Friction, |
| FrictionWeight |
|
|
| In the following image comparison, |
| UnionAsync() is called on the blue block |
| using a table containing the purple cylinder. The resulting |
| UnionOperation resolves into a shape of the combined geometry of |
| both parts. |
|
|
|
|
| Separate parts |
|
|
|
|
|
|
| Resulting UnionOperation |
|
|
| Notes |
|
|
| The original parts remain intact following a successful union operation. |
| In most cases, you should Destroy() all of the |
| original parts and parent the returned UnionOperation to the |
| same place as the calling BasePart. |
| By default, the resulting union respects the |
| Color property of each of its parts. To change |
| the entire union to a specific color, set its |
| UsePartColor property to true. |
| If an union operation would result in a part with more than 20,000 |
| triangles, it will be simplified to 20,000 triangles. |
| Parametersparts: ObjectsThe objects taking part in the union with the calling part.collisionfidelity: CollisionFidelityThe CollisionFidelity value for the resulting |
| UnionOperation.Default Value: "Default"renderFidelity: RenderFidelityThe RenderFidelity value of the resulting |
| PartOperation.Default Value: "Automatic"ReturnsInstanceResulting UnionOperation with default name Union.Code SamplesThis example demonstrates how to combine the geometry of one BasePart |
| with the geometry of other part(s) to form a UnionOperation.BasePart:UnionAsync()local mainPart = workspace.BlueBlock |
| local otherParts = {workspace.PurpleCylinder} |
|
|
| -- Perform union operation |
| local success, newUnion = pcall(function() |
| return mainPart:UnionAsync(otherParts) |
| end) |
|
|
| -- If operation succeeds, position it at the same location and parent it to the workspace |
| if success and newUnion then |
| newUnion.Position = mainPart.Position |
| newUnion.Parent = workspace |
| end |
|
|
| -- Destroy original parts which remain intact after operation |
| mainPart:Destroy() |
| for i = 1, #otherParts do |
| otherParts[i]:Destroy() |
| endMethods inherited from PVInstanceGetPivotCFrameWrite ParallelThis function gets the pivot of a PVInstance. This is often used |
| with PVInstance:PivotTo() to move a model. |
| Models and BaseParts are both |
| PVInstances ("Position Velocity Instances") and so both |
| have this function.ReturnsCFrameCode SamplesThis 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.Simple Character Teleportation-- This code should be placed in a LocalScript under StarterPlayerScripts |
| local Players = game:GetService("Players") |
| local ContextActionService = game:GetService("ContextActionService") |
|
|
| local player = Players.LocalPlayer |
|
|
| local function doTeleport(_actionName, inputState, _inputObject) |
| local character = player.Character |
| if character and character.Parent and inputState == Enum.UserInputState.Begin 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)PivotTovoidTransforms the PVInstance along with all of its descendant |
| PVInstances such that the pivot is now located at the |
| specified CFrame. This is the primary function that should be |
| used to move Models via scripting. |
| BaseParts are moved in this way by having their |
| CFrame transformed by the necessary offset. |
| 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 Position and |
| Orientation of BaseParts |
| moved in this way; they are only fired for CFrame. |
| When calling PivotTo on Models, |
| the offsets of the descendant parts and models are cached, such that |
| subsequent calls to PivotTo on the same model |
| do not accumulate floating point drift between the parts making up the |
| model. |
| Models and BaseParts are both |
| PVInstances ("Position Velocity Instances") and so both |
| have this function.ParameterstargetCFrame: CFrameThe CFrame that the PVInstance pivot should equal |
| after moving it.ReturnsvoidCode SamplesThis 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.Simple Character Teleportation-- This code should be placed in a LocalScript under StarterPlayerScripts |
| local Players = game:GetService("Players") |
| local ContextActionService = game:GetService("ContextActionService") |
|
|
| local player = Players.LocalPlayer |
|
|
| local function doTeleport(_actionName, inputState, _inputObject) |
| local character = player.Character |
| if character and character.Parent and inputState == Enum.UserInputState.Begin 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)Methods inherited from InstanceAddTagvoidThis method applies a tag to the instance, with no effect if the tag is |
| already applied. Successfully adding a tag will fire a signal created by |
| CollectionService:GetInstanceAddedSignal() with the given tag. |
| Note that when tagging an instance, it's common that some resources are |
| used to give the tag its functionality, for example event connections or |
| tables. To prevent memory leaks, it's a good idea to clean these up |
| (disconnect, set to nil, etc.) when no longer needed for a tag. Do this |
| when calling Instance:RemoveTag(), calling |
| Instance:Destroy(), or in a function connected to a signal |
| returned by CollectionService:GetInstanceRemovedSignal().Parameterstag: stringReturnsvoidClearAllChildrenvoidThis function destroys all of an Instance's children. |
| As Instance:Destroy() also calls itself on the children of an |
| object it is used on, this function will destroy all descendants. |
| Alternatives to ClearAllChildren |
| If the developer does not wish to destroy all descendants, they should use |
| Instance:GetChildren() or Instance:GetDescendants() to |
| loop through an object and select what to destroy. For example, the |
| following code sample will destroy all parts in an object. |
| for _, instance in pairs(object:GetDescendants()) do |
| if instance:IsA("BasePart") then |
| instance:Destroy() |
| end |
| endReturnsvoidCode SamplesThis example creates a Part and adds a few sparkle objects to the part. Then |
| it calls Part:ClearAllChildren() to remove all of the children.Instance:ClearAllChildrenlocal part = Instance.new("Part") |
|
|
| -- add some sparkles |
| for _ = 1, 3 do |
| local sparkles = Instance.new("Sparkles") |
| sparkles.Parent = part |
| end |
|
|
| print("Part has", #part:GetChildren(), "children") |
| --> Part has 3 children |
|
|
| part:ClearAllChildren() |
|
|
| print("Part has", #part:GetChildren(), "children") |
| --> Part has 0 childrenCloneInstanceClone creates a copy of an object and all of its descendants, ignoring |
| all objects that are not Archivable. The copy |
| of the root object is returned by this function and its |
| Parent is set to nil. |
| If a reference property such as ObjectValue.Value is set in a |
| cloned object, the value of the copy's property depends on original's |
| value: |
|
|
| If a reference property refers to an object that was also cloned, an |
| internal reference, the copy will refer to the copy. |
| If a reference property refers to an object that was not cloned, an |
| external reference, the same value is maintained in the copy. |
|
|
| This function is typically used to create models that can be regenerated. |
| First, get a reference to the original object. Then, make a copy of the |
| object and insert the copy by setting its Parent |
| to the Workspace or one of its descendants. Finally, when it's |
| time to regenerate the model, Destroy the copy |
| and clone a new one from the original like before.ReturnsInstanceCode SamplesThis code first references an existing object in the original variable. |
| Then, it makes a copy of the object, sets the parent to that of the original, |
| and finally moves the copy to (0, 50, 0).Clone Example-- Get a reference to an existing object |
| local original = workspace.Model |
| -- Create the model copy |
| local copy = original:Clone() |
| -- Parent the copy to the same parent as the original |
| copy.Parent = original.Parent |
| -- Move the copy so it's not overlapping the original |
| copy:SetPrimaryPartCFrame(CFrame.new(0, 50, 0))DestroyvoidSets the Instance.Parent property to nil, locks the |
| Instance.Parent property, disconnects all connections, and calls |
| Destroy on all children. This function is the correct way to dispose of |
| objects that are no longer required. Disposing of unneeded objects is |
| important, since unnecessary objects and connections in a place use up |
| memory (this is called a memory leak) which can lead to serious |
| performance issues over time. |
| Tip: After calling Destroy on an object, set any variables referencing |
| the object (or its descendants) to nil. This prevents your code from |
| accessing anything to do with the object. |
| local part = Instance.new("Part") |
| part.Name = "Hello, world" |
| part:Destroy() |
| -- Don't do this: |
| print(part.Name) --> "Hello, world" |
| -- Do this to prevent the above line from working: |
| part = nil |
| Once an Instance has been destroyed by this method it cannot be |
| reused because the Instance.Parent property is locked. To |
| temporarily remove an object, set Parent it to nil |
| instead. For example: |
| object.Parent = nil |
| wait(2) |
| object.Parent = workspace |
| To Destroy an object after a set amount of time, use |
| Debris:AddItem().ReturnsvoidCode SamplesInstance:Destroylocal Part = workspace.Part |
|
|
| Part:Destroy() |
|
|
| Part.Parent = workspace --> The Parent property of Part is lockedFindFirstAncestorInstanceWrite ParallelReturns the first ancestor of the Instance whose |
| Instance.Name is equal to the given name. |
| This function works upwards, meaning it starts at the Instance's |
| immediate Instance.Parent and works up towards the |
| DataModel. If no matching ancestor is found, it returns nil. |
| The following code snippet would find the first ancestor of the object |
| named 'Car'. |
| local car = object:FindFirstAncestor("Car") |
| For variants of this function that find ancestors of a specific class, |
| please see Instance:FindFirstAncestorOfClass() and |
| Instance:FindFirstAncestorWhichIsA().Parametersname: stringThe Instance.Name to be looked for.ReturnsInstanceThe Instance found.FindFirstAncestorOfClassInstanceWrite ParallelReturns the first ancestor of the Instance whose |
| Instance.ClassName is equal to the given className. |
| This function works upwards, meaning it starts at the Instance's |
| immediate Instance.Parent and works up towards the |
| DataModel. If no matching ancestor is found, it returns nil. |
| A common use of this function is finding the Model a |
| BasePart belongs to. For example: |
| local model = part:FindFirstAncestorOfClass("Model") |
| This function is a variant of Instance:FindFirstAncestor() which |
| checks the Instance.ClassName property rather than |
| Instance.Name. Instance:FindFirstAncestorWhichIsA() also |
| exists, using the Instance:IsA() method instead to respect class |
| inheritance.ParametersclassName: stringThe Instance.ClassName to be looked for.ReturnsInstanceThe Instance found.FindFirstAncestorWhichIsAInstanceWrite ParallelReturns the first ancestor of the Instance for whom |
| Instance:IsA() returns true for the given className. |
| This function works upwards, meaning it starts at the Instance's |
| immediate Instance.Parent and works up towards the |
| DataModel. If no matching ancestor is found, it returns nil. |
| Unlike Instance:FindFirstAncestorOfClass(), this function uses |
| Instance:IsA() which respects class inheritance. For example: |
| print(part:IsA("Part")) --> true |
| print(part:IsA("BasePart")) --> true |
| print(part:IsA("Instance")) --> true |
| Therefore, the following code sample will return the first |
| BasePart ancestor, regardless of if it is a WedgePart, |
| MeshPart or Part. |
| local part = object:FindFirstAncestorWhichIsA("BasePart") |
| See also, Instance:FindFirstAncestor().ParametersclassName: stringThe Instance.ClassName to be looked for.ReturnsInstanceThe Instance found.FindFirstChildInstanceWrite ParallelReturns the first child of the Instance with the given name, |
| or nil if no such child exists. If the optional recursive argument is |
| true, this function searches all descendants rather than only the |
| immediate children of the Instance. |
| Checking the Existence of an Object |
| FindFirstChild is necessary if you need to verify an object exists before |
| continuing. Attempting to index a child by name using the dot operator |
| throws an error if the child doesn't exist. |
| -- The following line errors if Part doesn't exist in the Workspace: |
| workspace.Part.Transparency = 0.5 |
| Use FindFirstChild to first check for Part, then use an if-statement to |
| run code that needs it. |
| local part = workspace:FindFirstChild("Part") |
| if part then |
| part.Transparency = 0.5 |
| end |
| Finding a Child Whose Name Matches a Property |
| Sometimes the Name of an object is the same as that |
| of a property of its Parent. When using the dot |
| operator, properties take precedence over children if they share a name. |
| In the following example, a Folder called "Color" is added to a |
| Part, which also has the Part.Color property. |
| Part.Color refers to the Color3, not the Folder. |
| local part = Instance.new("Part") |
| local folder = Instance.new("Folder") |
| folder.Name = "Color" |
| folder.Parent = part |
| local c = part.Color --> A Color3 |
| local c2 = part:FindFirstChild("Color") --> The Folder |
| A benefit of using FindFirstChild() in |
| this way is that the introduction of new properties does not impose a risk |
| on your code. |
| Performance Note |
| FindFirstChild() takes about 20% longer |
| than using the dot operator and almost 8 times longer than simply storing |
| a reference to an object. Therefore, you should avoid calling it in |
| performance-dependent code such as in tight loops or functions connected |
| to RunService.Heartbeat and RunService.RenderStepped. |
| Instead, store the result in a variable, or consider using |
| ChildAdded or |
| WaitForChild() to detect when a child of a |
| given name becomes available.Parametersname: stringThe Instance.Name to be searched for.recursive: booleanWhether or not the search should be conducted recursively.Default Value: falseReturnsInstanceThe Instance found.Code SamplesThe below would look in Workspace for an object name "Brick". If found, it |
| will change the name of the object to "Foo".Instance:FindFirstChildlocal found = workspace:FindFirstChild("Brick") |
|
|
| if found then |
| found.Name = "Foo" |
| endFindFirstChildOfClassInstanceWrite ParallelReturns the first child of the Instance whose |
| ClassName is equal to the given className. |
| If no matching child is found, this function returns nil. |
| Unlike Instance:FindFirstChildWhichIsA() this function uses only |
| returns objects whose class matches the given className, ignoring class |
| inheritance. |
| Developers looking for a child by name should use |
| Instance:FindFirstChild() instead.ParametersclassName: stringThe Instance.ClassName to be looked for.ReturnsInstanceThe Instance found.Code SamplesInstance:FindFirstChildOfClasslocal Players = game:GetService("Players") |
|
|
| local player = Players.LocalPlayer |
| local character = player.Character or player.CharacterAdded:Wait() |
|
|
| local humanoid |
|
|
| while not humanoid do |
| humanoid = character:FindFirstChildOfClass("Humanoid") |
| if not humanoid then |
| character.ChildAdded:Wait() |
| end |
| endFindFirstChildWhichIsAInstanceWrite ParallelReturns the first child of the Instance for whom |
| Instance:IsA() returns true for the given className. |
| If no matching child is found, this function returns nil. If the optional |
| recursive argument is true, this function searches all descendants rather |
| than only the immediate children of the Instance. |
| Unlike Instance:FindFirstChildOfClass(), this function uses |
| Instance:IsA() which respects class inheritance. For example: |
| print(part:IsA("Part")) --> true |
| print(part:IsA("BasePart")) --> true |
| print(part:IsA("Instance")) --> true |
| Therefore, the following code sample will return the first |
| BasePart child, regardless of if it is a WedgePart, |
| MeshPart or Part. |
| local part = object:FindFirstChildWhichIsA("BasePart") |
| Developers looking for a child by name, should use |
| Instance:FindFirstChild() instead.ParametersclassName: stringThe Instance.ClassName to be searched for.recursive: booleanWhether or not the search should be conducted recursively.Default Value: falseReturnsInstanceThe Instance found.FindFirstDescendantInstanceWrite ParallelReturns the first descendant found with the given Instance.Name.Parametersname: stringThe Instance.Name to search for.ReturnsInstanceThe Instance found.GetActorActorWrite ParallelIf the Instance is an Actor, the Actor itself is |
| returned. Otherwise, its closest ancestor Actor is returned. If no |
| ancestor is an Actor, the result is nil.ReturnsActorThe Actor found.GetAttributeVariantWrite ParallelThis function returns the attribute which has been assigned to the given |
| name. If no attribute has been assigned then nil is returned. |
| For example, the following code snippet will set the value of the |
| instance's InitialPostion attribute. Note that this code sample does not |
| define Instance: |
| local initialPosition = instance:GetAttribute("InitialPosition") |
| See also: |
|
|
| Instance:SetAttribute(), sets the attribute with the given name |
| to the given value |
| Instance:GetAttributes(), returns a dictionary of string → |
| variant pairs for each of the instance's attributes |
| Instance.AttributeChanged, fires whenever an attribute is |
| changed on the instance |
| Instance:GetAttributeChangedSignal(), returns an event that |
| fires when the given attribute changes |
| Parametersattribute: stringThe name of the attribute being retrieved.ReturnsVariantThe attribute which has been assigned to the given name. If no |
| attribute has been assigned then nil is returned.GetAttributeChangedSignalRBXScriptSignalThis function returns an event that behaves exactly like the Changed |
| event, except that the event only fires when the given attribute changes. |
| It's generally a good idea to use this method instead of a connection to |
| Changed with a function that checks the attribute name. Subsequent calls |
| to this method on the same object with the same attribute name return the |
| same event. |
| It is similar to Instance:GetPropertyChangedSignal() but for |
| attributes. |
| For example, the following code snippet will return a signal that fires |
| the function Instance.AttributeChanged when the instance's |
| InitialPosition attribute changes. Note that this code sample does not |
| define Instance: |
| local function attributeChanged() |
| print("Attribute changed") |
| end |
|
|
| instance:GetAttributeChangedSignal("InitialPosition"):Connect(attributeChanged) |
| See also: |
|
|
| Instance:SetAttribute(), sets the attribute with the given name |
| to the given value |
| Instance:GetAttribute(), returns the attribute which has been |
| assigned to the given name |
| Instance:GetAttributes(), returns a dictionary of string → |
| variant pairs for each of the instance's attributes |
| Instance.AttributeChanged, fires whenever an attribute is |
| changed on the instance |
| Parametersattribute: stringThe name of the specified attribute for which the change signal is |
| being returned.ReturnsRBXScriptSignalAn event that fires when the given attribute changes.GetAttributestableWrite ParallelThis function returns a dictionary of string → variant pairs for each |
| attribute where the string is the name of the attribute and the variant is |
| a non-nil value. |
| For example, the following code snippet will print an instance's |
| attributes and values. Note that this code sample does not define |
| Instance: |
| local attributes = instance:GetAttributes() |
| for name, value in pairs(attributes) do |
| print(name .. " " .. value) |
| end |
| See also: |
|
|
| Instance:SetAttribute(), sets the attribute with the given name |
| to the given value |
| Instance:GetAttribute(), returns the attribute which has been |
| assigned to the given name |
| Instance.AttributeChanged, fires whenever an attribute is |
| changed on the instance |
| Instance:GetAttributeChangedSignal(), returns an event that |
| fires when the given attribute changes |
| ReturnstableA dictionary of string → variant pairs for each attribute where the |
| string is the name of the attribute and the variant is a non-nil |
| value.GetChildrenObjectsWrite ParallelReturns an array (a numerically indexed table) containing all of the |
| Instance's direct children, or every Instance whose |
| Parent is equal to the object. The array can be |
| iterated upon using either a numeric or generic for-loop: |
| -- Numeric for-loop example |
| local children = workspace:GetChildren() |
| for i = 1, #children do |
| local child = children[i] |
| print(child.Name .. " is child number " .. i) |
| end |
| -- Generic for-loop example |
| local children = workspace:GetChildren() |
| for i, child in ipairs(children) do |
| print(child.Name .. " is child number " .. i) |
| end |
| The children are sorted by the order in which their |
| Parent property was set to the object. |
| See also the GetDescendants function.ReturnsObjectsAn array containing the Instance's children.Code SamplesThe below would print the name of all objects currently in Workspace when ran.Instance:GetChildrenlocal children = workspace:GetChildren() |
|
|
| for i = 1, #children do |
| print(i, children[i].Name) |
| endGetDebugIdstringNot BrowsablePlugin SecurityReturns a coded string of the Instances DebugId used internally by |
| Roblox. |
| Note: |
|
|
| This item is protected. Attempting to use it in a Script or |
| LocalScript will cause an error |
| A debug ID is an ID used in debugging processes. It allows a debugger to |
| read each instruction before an application processes it. All objects in |
| Roblox act like processes and each run instructions (or 'code') that can |
| be debugged if needed |
| This can be helpful for plugins which need to distinguish similar |
| objects from one-another (such as objects that share the same name) |
| ParametersscopeLength: numberThe scope length.Default Value: 4ReturnsstringThe Debug ID string.Code SamplesInstance:GetDebugIdprint(workspace:GetDebugId()) --> 39FA_12 |
| print(workspace:GetDebugId(10)) --> 39FA2FEF4D_12 |
| print(workspace:GetDebugId(math.huge)) --> 12GetDescendantsArrayCustom Lua StateWrite ParallelThe GetDescendants function of an object returns an array that |
| contains all of the descendants of that object. Unlike |
| Instance:GetChildren(), which only returns the immediate children |
| of an object, GetDescendants will find every child of the object, every |
| child of those children, and so on. |
| The arrays returned by GetDescendants are arranged so that parents come |
| earlier than their children. Refer to the following example of a |
| Model in the Workspace: |
|
|
| Inside this model are three parts (C, D, and E) and another model |
| (InnerModel). Inside the inner model are two more parts (A and B). Calling |
| GetDescendants on the first model and printing the contents of the |
| returned array would print the first level of children (InnerModel, C, D, |
| and E) before A and B. |
| local descendants = game.Workspace.Model:GetDescendants() |
|
|
| -- Loop through all of the descendants of the model and |
| -- print out their name |
| for index, descendant in pairs(descendants) do |
| print(descendant.Name) |
| end |
|
|
| -- Prints: |
| -- C |
| -- D |
| -- E |
| -- InnerModel |
| -- A |
| -- BReturnsArrayAn array containing the Instance's descendants.Code SamplesGetDescendants is often used to do something to all the descendants that are a |
| particular type of object. The code in this example uses GetDescendants and |
| Instance:IsA() to find all of the parts in the workspace and turns |
| them green.Instance:GetDescendantslocal descendants = workspace:GetDescendants() |
|
|
| -- Loop through all of the descendants of the Workspace. If a |
| -- BasePart is found, the code changes that parts color to green |
| for _, descendant in pairs(descendants) do |
| if descendant:IsA("BasePart") then |
| descendant.BrickColor = BrickColor.Green() |
| end |
| endGetFullNamestringWrite ParallelReturns a string describing the Instance's ancestry. The string is |
| a concatenation of the Name of the object and its |
| ancestors, separated by periods. The DataModel (game) is not |
| considered. For example, a Part in the Workspace may |
| return Workspace.Part. |
| When called on an Instance that is not a descendant of the |
| DataModel, this function considers all ancestors up to and |
| including the topmost one without a Parent. |
| This function is useful for logging and debugging. You shouldn't attempt |
| to parse the returned string for any useful operation; this function does |
| not escape periods (or any other symbol) in object names. In other words, |
| although its output often appears to be a valid Lua identifier, it is not |
| guaranteed.ReturnsstringThe full name of the Instance.Code SamplesThis code sample demonstrates the behavior of Instance:GetFullName(). |
| It shows how the function behaves when called on an object not in the |
| DataModel hierarchy, and it also shows how the return value does not escape |
| special characters.Instance:GetFullName-- Create a simple hierarchy |
| local model = Instance.new("Model") |
| local part = Instance.new("Part") |
| part.Parent = model |
| local fire = Instance.new("Fire") |
| fire.Parent = part |
|
|
| print(fire:GetFullName()) --> Model.Part.Fire |
|
|
| model.Parent = workspace |
|
|
| print(fire:GetFullName()) --> Workspace.Model.Part.Fire |
|
|
| part.Name = "Hello, world" |
|
|
| print(fire:GetFullName()) --> Workspace.Model.Hello, world.FireThis code sample re-implements the Instance:GetFullName() function in |
| Lua.Instance:GetFullName Lua Implementationlocal function getFullName(object) |
| local result = object.Name |
| object = object.Parent |
| while object and object ~= game do |
| -- Prepend parent name |
| result = object.Name .. "." .. result |
| -- Go up the hierarchy |
| object = object.Parent |
| end |
| return result |
| end |
|
|
| print(getFullName(workspace.Camera)) --> Workspace.CameraGetPropertyChangedSignalRBXScriptSignalThis method returns an event that behaves exactly like the Changed |
| event, except that the event only fires when the given property changes. |
| It's generally a good idea to use this method instead of a connection to |
| Changed with a function that checks the property name. Subsequent calls |
| to this method on the same object with the same property name return the |
| same event. |
| print(object:GetPropertyChangedSignal("Name") == object:GetPropertyChangedSignal("Name")) --> always true |
| ValueBase objects, such as IntValue and |
| StringValue, use a modified Changed event that fires with the |
| contents of the Value property. As such, this method provides a way to |
| detect changes in other properties of those objects. For example, to |
| detect changes in the Name property of an IntValue, use |
| IntValue:GetPropertyChangedSignal("Name"):Connect(someFunc) since the |
| Changed event of IntValue objects only detect changes on the |
| Value property.Parametersproperty: stringThe property to connect to.ReturnsRBXScriptSignalA signal that fires whenever the property changes.Code SamplesThis code sample demonstrates how to save a value before a changed event fires |
| on it in order to get more information about a change.Old-to-New Values with Changedlocal part = Instance.new("Part") |
|
|
| local currentColor = part.BrickColor |
|
|
| local function onBrickColorChanged() |
| local newColor = part.BrickColor |
| print("Color changed from", currentColor.Name, "to", newColor.Name) |
| currentColor = newColor |
| end |
| part:GetPropertyChangedSignal("BrickColor"):Connect(onBrickColorChanged) |
|
|
| part.BrickColor = BrickColor.new("Really red") |
| part.BrickColor = BrickColor.new("Really blue")This code sample demonstrates the equivalence of the Changed event and event |
| returned by GetPropertyChangedSignal.Changed and GetPropertyChangedSignallocal part = Instance.new("Part") |
|
|
| local function onBrickColorChanged() |
| print("My color is now " .. part.BrickColor.Name) |
| end |
|
|
| local function onChanged(property) |
| if property == "BrickColor" then |
| onBrickColorChanged() |
| end |
| end |
|
|
| part:GetPropertyChangedSignal("BrickColor"):Connect(onBrickColorChanged) |
| part.Changed:Connect(onChanged) |
|
|
| -- Trigger some changes (because we connected twice, |
| -- both of these will cause two calls to onBrickColorChanged) |
| part.BrickColor = BrickColor.new("Really red") |
| part.BrickColor = BrickColor.new("Institutional white")GetTagsArrayWrite ParallelThis method returns an array of the tags applied to the given instance, as |
| strings. You can add tags either in Studio in the |
| Properties window or at runtime with |
| AddTag(). |
| This method is useful when you want to do something with multiple tags on |
| an instance at once. However, it is inefficient to use this method to |
| check for the existence of a single tag; instead, use |
| HasTag() to check for a specific tag.ReturnsArrayHasTagbooleanWrite ParallelThis method returns true if the provided tag has been added to the |
| object. You can add tags either in Studio in the |
| Properties window or at runtime with |
| AddTag().Parameterstag: stringReturnsbooleanIsAbooleanCustom Lua StateWrite ParallelIsA returns true if the Instance's class is equivalent to or a |
| subclass of a given class. This function is similar to the |
| instanceof operators in other languages, and is a form of |
| type introspection. To |
| ignore class inheritance, test the ClassName |
| property directly instead. For checking native Lua data types (number, |
| string, etc) use the functions type and typeof. |
| Most commonly, this function is used to test if an object is some kind of |
| part, such as Part or WedgePart, which inherits from |
| BasePart (an abstract class). For example, if your goal is to |
| change all of a Character's limbs to the same |
| color, you might use GetChildren to iterate |
| over the children, then use IsA to filter non-BasePart objects |
| which lack the BrickColor property: |
| local function paintFigure(character, color) |
| -- Iterate over the child objects of the character |
| for _, child in pairs(character:GetChildren()) do |
| -- Filter out non-part objects, such as Shirt, Pants and Humanoid |
| -- R15 use MeshPart and R6 use Part, so we use BasePart here to detect both: |
| if child:IsA("BasePart") then |
| child.BrickColor = color |
| end |
| end |
| end |
| paintFigure(game.Players.Player.Character, BrickColor.new("Bright blue")) |
| Since all classes inherit from Instance, calling |
| object:IsA("Instance") will always return true.ParametersclassName: stringThe class against which the Instance's class will be checked. |
| Case-sensitive.ReturnsbooleanDescribes whether the Instance's class matched or is a subclass of the |
| given class.Code SamplesUsage of IsA to test class inheritance:Instance:IsAprint(workspace:IsA("Instance")) --> true |
| print(workspace:IsA("Workspace")) --> true |
| print(game:IsA("workspace")) --> false |
| print(game:IsA("DataModel")) --> trueIsAncestorOfbooleanWrite ParallelReturns true if an Instance is an ancestor of the given |
| descendant. |
| An Instance is considered the ancestor of an object if the |
| object's Instance.Parent or one of it's parent's |
| Instance.Parent is set to the Instance. |
| See also, Instance:IsDescendantOf().Parametersdescendant: InstanceThe descendant Instance.ReturnsbooleanTrue if the Instance is an ancestor of the given descendant.Code SamplesInstance:IsAncestorOfprint(workspace:IsAncestorOf(workspace.Player.HumanoidRootPart)) --> trueIsDescendantOfbooleanWrite ParallelReturns true if an Instance is a descendant of the given ancestor. |
| An Instance is considered the descendant of an object if the |
| Instance's parent or one of its parent's parent is set to the |
| object. |
| Note, DataModel is a descendant of nil. This means IsDescendantOf |
| cannot be used with a parameter of nil to check if an object has been |
| removed. |
| See also, Instance:IsAncestorOf().Parametersancestor: InstanceThe ancestor Instance.ReturnsbooleanTrue if the Instance is a descendant of the given ancestor.Code SamplesInstance:IsDescendantOflocal part = Instance.new("Part") |
| print(part:IsDescendantOf(game)) |
| --> false |
|
|
| part.Parent = workspace |
| print(part:IsDescendantOf(game)) |
| --> true |
|
|
| part.Parent = game |
| print(part:IsDescendantOf(game)) |
| --> trueRemovevoidDEPRECATEDDEPRECATEDThis item is deprecated in favor of Instance:Destroy() and |
| Instance:ClearAllChildren(). If you must remove an object from the |
| game, and wish to use the object later, set its Parent property to nil |
| instead of using this method.The Remove function sets the object's Instance.Parent to nil, and |
| does the same for all its descendants. |
| If the object is referenced before being removed it is possible to |
| retrieve the object at a later point.ReturnsvoidCode SamplesThe following code demonstrates how a part can be re-added to the DataModel |
| after being removed:Instance:Removelocal part = Instance.new("Part") |
| part.Parent = workspace |
| print(part.Parent) --> Workspace |
|
|
| part:Remove() |
|
|
| print(part.Parent) --> nil |
|
|
| part.Parent = workspace |
|
|
| print(part.Parent) --> WorkspaceRemoveTagvoidThis method removes a tag from an instance. It will not throw an error if |
| the object does not have the tag. Successfully removing a tag will fire a |
| signal created by CollectionService:GetInstanceRemovedSignal() |
| with the given tag. |
| Note that when tagging an instance, it's common that some resources are |
| used to give the tag its functionality, for example event connections or |
| tables. To prevent memory leaks, it's a good idea to clean these up |
| (disconnect, set to nil, etc.) when no longer needed for a tag.Parameterstag: stringReturnsvoidSetAttributevoidThis function sets the attribute with the given name to the given value. |
| If the value given is nil, then the attribute will be removed (since nil |
| is returned by default). |
| For example, the following code snippet will set the instance's |
| InitialPosition attribute to Vector3.new(0, 0, 0). |
| Note that this code sample does not define Instance: |
| instance:SetAttribute("InitialPosition", Vector3.new(0, 0, 0)) |
| Limitations |
| Naming requirements and restrictions: |
|
|
| Names must only use alphanumeric characters and underscore |
| No spaces or unique symbols are allowed |
| Strings must be 100 characters or less |
| Names are not allowed to start with RBX unless the caller is a Roblox |
| core-script (reserved for Roblox) |
|
|
| When attempting to set an attribute to an unsupported type, an error will |
| be thrown. |
| See also: |
|
|
| Instance:GetAttribute(), returns the attribute which has been |
| assigned to the given name |
| Instance:GetAttributes(), returns a dictionary of string → |
| variant pairs for each of the instance's attributes |
| Instance.AttributeChanged, fires whenever an attribute is |
| changed on the instance |
| Instance:GetAttributeChangedSignal(), returns an event that |
| fires when the given attribute changes |
| Parametersattribute: stringThe name of the attribute being set.value: VariantThe value that the specified attribute is being set to.ReturnsvoidWaitForChildInstanceCustom Lua StateCan YieldReturns the child of the Instance with the given name. If the |
| child does not exist, it will yield the current thread until it does. If |
| the timeOut parameter is specified, this method will time out after the |
| specified number of seconds and return nil. |
| Primary Usage |
| WaitForChild() is extremely important when |
| working on code run by the client in a LocalScript. The Roblox |
| engine does not guarantee the time or order in which objects are |
| replicated from the server to the client. Additionally, if an experience |
| has Workspace.StreamingEnabled set to true, |
| BaseParts that are far away from the player's character |
| may not be streamed to the client, potentially causing scripts to break |
| when indexing objects that do not yet exist on the client. |
| Notes |
|
|
|
|
| This function does not yield if a child with the given name exists when |
| the call is made. |
|
|
|
|
| Instance:FindFirstChild() is a more efficient alternative to |
| WaitForChild() for objects that are |
| assumed to exist. |
|
|
|
|
| If a call to this method exceeds 5 seconds without returning, and no |
| timeOut parameter has been specified, a warning will be printed to the |
| output that the thread may yield indefinitely. This warning takes the |
| following form where X is the parent's name and Y is the child's |
| name: |
| Infinite yield possible on 'X:WaitForChild("Y")' |
|
|
| ParameterschildName: stringThe Instance.Name to be looked for.timeOut: numberAn optional time out parameter.ReturnsInstanceThe Instance found.Code SamplesThe following code waits for an instance named "Part" to be added to |
| Workspace.Instance:WaitForChildlocal part = workspace:WaitForChild("Part") |
| print(part.Name .. " has been added to the Workspace")childrenObjectsDEPRECATEDDEPRECATEDThis item has been superseded by Instance:GetChildren() which |
| should be used in all new work.The children function returns an array of the object's children.ReturnsObjectsArray of child objects/instances.cloneInstanceDEPRECATEDDEPRECATEDThis deprecated function is a variant of Instance:Clone() which |
| should be used instead.ReturnsInstancedestroyvoidDEPRECATEDDEPRECATEDThis deprecated function is a variant of Instance:Destroy() which |
| should be used instead.ReturnsvoidfindFirstChildInstanceDEPRECATEDDEPRECATEDThis deprecated function is a variant of Instance:FindFirstChild() |
| which should be used instead.Parametersname: stringrecursive: booleanDefault Value: falseReturnsInstancegetChildrenObjectsDEPRECATEDDEPRECATEDThis deprecated function is a variant of Instance:GetChildren() |
| which should be used instead.ReturnsObjectsisAbooleanDEPRECATEDCustom Lua StateDEPRECATEDThis deprecated function is a variant of Instance:IsA() which |
| should be used instead.ParametersclassName: stringReturnsbooleanisDescendantOfbooleanDEPRECATEDDEPRECATEDThis deprecated function is a variant of Instance:IsDescendantOf() |
| which should be used instead.Parametersancestor: InstanceReturnsbooleanremovevoidDEPRECATEDDEPRECATEDThis deprecated function is a variant of Instance:Remove() which |
| has also been deprecated. Neither function should be used in new work.ReturnsvoidEventsEvents inherited from BasePartLocalSimulationTouchedDEPRECATEDDEPRECATEDThis event is deprecated in favor of BasePart.Touched.Fired when another part comes in contact with another object. This event |
| only sends data to the client notifying it that two parts have collided, |
| whereas BasePart.Touched sends data to the server.Parameterspart: BasePartCode SamplesBasePart.LocalSimulationTouchedworkspace.Part.LocalSimulationTouched:Connect(function(part) |
| print(part.Name) |
| end)OutfitChangedDEPRECATEDDEPRECATEDThis event is deprecated. Do not use it for new work.Fired if the part's appearance is affected by the Shirt class.StoppedTouchingDEPRECATEDDEPRECATEDThis event is deprecated in favor of BasePart.TouchEnded, which |
| should be used instead.ParametersotherPart: BasePartTouchEndedFires when a part stops touching another part under similar conditions to |
| those of BasePart.Touched. |
| This event works in conjunction with |
| Workspace.TouchesUseCollisionGroups to specify whether |
| collision groups |
| are acknowledged for detection.ParametersotherPart: BasePartCode SamplesThis code sample creates a BillboardGui on a part that displays the number of |
| parts presently touching it.Touching Parts Countlocal part = script.Parent |
|
|
| local billboardGui = Instance.new("BillboardGui") |
| billboardGui.Size = UDim2.new(0, 200, 0, 50) |
| billboardGui.Adornee = part |
| billboardGui.AlwaysOnTop = true |
| billboardGui.Parent = part |
|
|
| local tl = Instance.new("TextLabel") |
| tl.Size = UDim2.new(1, 0, 1, 0) |
| tl.BackgroundTransparency = 1 |
| tl.Parent = billboardGui |
|
|
| local numTouchingParts = 0 |
|
|
| local function onTouch(otherPart) |
| print("Touch started: " .. otherPart.Name) |
| numTouchingParts = numTouchingParts + 1 |
| tl.Text = numTouchingParts |
| end |
|
|
| local function onTouchEnded(otherPart) |
| print("Touch ended: " .. otherPart.Name) |
| numTouchingParts = numTouchingParts - 1 |
| tl.Text = numTouchingParts |
| end |
|
|
| part.Touched:Connect(onTouch) |
| part.TouchEnded:Connect(onTouchEnded)TouchedThe Touched event fires when a part comes in contact with another |
| part. For instance, if PartA bumps into PartB, then |
| PartA.Touched fires with PartB, and |
| PartB.Touched fires with PartA. |
| This event only fires as a result of physical movement, so it will not |
| fire if the CFrame property was changed such that |
| the part overlaps another part. This also means that at least one of the |
| parts involved must not be Anchored at the |
| time of the collision. |
| This event works in conjunction with |
| Workspace.TouchesUseCollisionGroups to specify whether |
| collision groups |
| are acknowledged for detection.ParametersotherPart: BasePartThe other part that came in contact with the given part.Code SamplesThis code sample creates a BillboardGui on a part that displays the number of |
| parts presently touching it.Touching Parts Countlocal part = script.Parent |
|
|
| local billboardGui = Instance.new("BillboardGui") |
| billboardGui.Size = UDim2.new(0, 200, 0, 50) |
| billboardGui.Adornee = part |
| billboardGui.AlwaysOnTop = true |
| billboardGui.Parent = part |
|
|
| local tl = Instance.new("TextLabel") |
| tl.Size = UDim2.new(1, 0, 1, 0) |
| tl.BackgroundTransparency = 1 |
| tl.Parent = billboardGui |
|
|
| local numTouchingParts = 0 |
|
|
| local function onTouch(otherPart) |
| print("Touch started: " .. otherPart.Name) |
| numTouchingParts = numTouchingParts + 1 |
| tl.Text = numTouchingParts |
| end |
|
|
| local function onTouchEnded(otherPart) |
| print("Touch ended: " .. otherPart.Name) |
| numTouchingParts = numTouchingParts - 1 |
| tl.Text = numTouchingParts |
| end |
|
|
| part.Touched:Connect(onTouch) |
| part.TouchEnded:Connect(onTouchEnded)This code sample demonstrates how to connect the BasePart.Touched event of multiple parts in a Model to one function.Model Touchedlocal model = script.Parent |
|
|
| local function onTouched(otherPart) |
| -- Ignore instances of the model coming in contact with itself |
| if otherPart:IsDescendantOf(model) then return end |
| |
| print(model.Name .. " collided with " .. otherPart.Name) |
| end |
|
|
| for _, child in pairs(model:GetChildren()) do |
| if child:IsA("BasePart") then |
| child.Touched:Connect(onTouched) |
| end |
| endEvents inherited from InstanceAncestryChangedFires when the Instance.Parent property of the object or one of |
| its ancestors is changed. |
| This event includes two parameters, child and parent. Child refers |
| to the Instance whose Instance.Parent was actually |
| changed. Parent refers to this Instance's new |
| Instance.Parent. |
| You can use this event to track the deletion of an instance in Studio, |
| such as manual deletion in the Explorer or through a plugin. If you need |
| to detect when an instance is destroyed using Instance:Destroy(), |
| use the Instance.Destroying event instead.Parameterschild: InstanceThe Instance whose Instance.Parent has been changed.parent: InstanceThe new Instance.Parent of the Instance whose |
| Instance.Parent was changed.Code SamplesThe below example would print "Part is now a child of Model".Instance.AncestryChangedlocal part = Instance.new("Part") |
| part.Parent = workspace |
|
|
| local function onAncestryChanged(child, parent) |
| print(child.Name .. " is now a child of " .. parent.Name) |
| end |
|
|
| part.AncestryChanged:Connect(onAncestryChanged) |
|
|
| part.Parent = workspace.ModelAttributeChangedThis event fires whenever an attribute is changed on the instance. This |
| includes when an attribute is set to nil. The name of the attribute that |
| has been changed is passed to the connected function. |
| For example, the following code snippet will connect the |
| AttributeChanged function to fire whenever one of Instance's |
| attributes changes. Note that this code sample does not define |
| Instance: |
| local function attributeChanged(attributeName) |
| print(attributeName, "changed") |
| end |
|
|
| instance.AttributeChanged:Connect(attributeChanged) |
| See also: |
|
|
| Instance:SetAttribute(), sets the attribute with the given name |
| to the given value |
| Instance:GetAttribute(), returns the attribute which has been |
| assigned to the given name |
| Instance:GetAttributes(), returns a dictionary of string → |
| variant pairs for each of the instance's attributes |
| Instance:GetAttributeChangedSignal(), returns an event that |
| fires when the given attribute changes |
| Parametersattribute: stringThe name of the attribute that has been changed.ChangedThe Changed event fires right after most properties change on objects. It |
| is possible to find the present value of a changed property by using |
| object[property]. To get the value of a property before it changes, you |
| must have stored the value of the property before it changed. |
| If you are only interested in listening to the change of a specific |
| property, consider using the GetPropertyChangedSignal method instead to |
| get an event that only fires when a given property changes. |
| This event does not fire for physics-related changes, like when the |
| CFrame, Velocity, RotVelocity, Position, Orientation |
| and CFrame properties of a BasePart change due to |
| gravity. To detect changes in these properties, consider using a |
| physics-based event like RunService.Stepped or |
| BasePart.Touched. A while-true-do loop can also work. |
| For "-Value" objects, this event behaves differently: it only fires when |
| the Value property changes. See individual pages for IntValue, |
| StringValue, etc for more information. To detect other changes in |
| these objects, you must use GetPropertyChangedSignal instead.Parametersproperty: stringThe name of the property that changed.Code SamplesThis sample demonstrates the subtleties of the Changed event on normal objects |
| and "-Value" objects.Changed Event-- Demonstrate the Changed event by creating a Part |
| local part = Instance.new("Part") |
| part.Changed:Connect(print) |
| -- This fires Changed with "Transparency" |
| part.Transparency = 0.5 |
| -- Similarly, this fires Changed with "Number" |
| part.Name = "SomePart" |
| -- Since changing BrickColor will also change other |
| -- properties at the same time, this line fires Changed |
| -- with "BrickColor", "Color3" and "Color3uint16". |
| part.BrickColor = BrickColor.Red() |
|
|
| -- A NumberValue holds a double-precision floating-point number |
| local vNumber = Instance.new("NumberValue") |
| vNumber.Changed:Connect(print) |
| -- This fires Changed with 123.456 (not "Value") |
| vNumber.Value = 123.456 |
| -- This does not fire Changed |
| vNumber.Name = "SomeNumber" |
|
|
| -- A StringValue stores one string |
| local vString = Instance.new("StringValue") |
| vString.Changed:Connect(print) |
| -- This fires Changed with "Hello" (not "Value") |
| vString.Value = "Hello"This code sample demonstrates the Changed event firing within a parent object.Change Detectorlocal object = script.Parent |
|
|
| local function onChanged(property) |
| -- Get the current value of the property |
| local value = object[property] |
| -- Print a message saying what changed |
| print(object:GetFullName() .. "." .. property .. " (" .. typeof(value) .. ") changed to " .. tostring(value)) |
| end |
|
|
| object.Changed:Connect(onChanged) |
| -- Trigger a simple change in the object (add an underscore to the name) |
| object.Name = "_" .. object.NameChildAddedFires after an object is parented to this Instance. |
| Note, when using this function on a client to detect objects created by |
| the server it is necessary to use Instance:WaitForChild() when |
| indexing these object's descendants. This is because the object and its |
| descendants are not guaranteed to replicate from the server to the client |
| simultaneously. For example: |
| workspace.ChildAdded:Connect(function(child) |
| -- need to use WaitForChild as descendants may not have replicated yet |
| local head = child:WaitForChild("Head") |
| end) |
| Note, this function only works for immediate children of the |
| Instance. For a function that captures all descendants, use |
| Instance.DescendantAdded. |
| See also, Instance.ChildRemoved.Parameterschild: InstanceThe Instance that has been added.Code SamplesThis snippet prints the names of objects as they are added to the Workspace:Instance.ChildAddedlocal function onChildAdded(instance) |
| print(instance.Name .. " added to the workspace") |
| end |
|
|
| workspace.ChildAdded:Connect(onChildAdded) |
|
|
| local part = Instance.new("Part") |
| part.Parent = workspace --> Part added to the WorkspaceChildRemovedFires after a child is removed from this Instance. |
| Removed refers to when an object's parent is changed from this |
| Instance to something other than this Instance. Note, this |
| event will also fire when a child is destroyed (using |
| Instance:Destroy()) as the destroy function sets an object's |
| parent to nil. |
| This function only works for immediate children of the Instance. |
| For a function that captures all descendants, use |
| Instance.DescendantRemoving. |
| See also Instance.ChildAdded.Parameterschild: InstanceThe Instance that has been removed.Code SamplesThis snippet prints the names of objects as they are removed from the |
| Workspace:Instance.ChildRemovedlocal function onChildRemoved(instance) |
| print(instance.Name .. " removed from the workspace") |
| end |
|
|
| workspace.ChildRemoved:Connect(onChildRemoved) |
|
|
| local part = Instance.new("Part") |
| part.Parent = workspace |
|
|
| task.wait(2) |
|
|
| part:Destroy()DescendantAddedThe DescendantAdded event fires after a descendant is added to the |
| Instance. |
| As DescendantAdded fires for every descendant, parenting an object to the |
| Instance will fire the event for this object and all of its |
| descendants individually. |
| Developers only concerned with the immediate children of the |
| Instance should use Instance.ChildAdded instead. |
| See also Instance.DescendantRemoving.Parametersdescendant: InstanceThe Instance that has been added.Code SamplesThis following example will print the name of any object that is added to the |
| Workspace:Instance.DescendantAddedlocal function onDescendantAdded(descendant) |
| print(descendant) |
| end |
|
|
| workspace.DescendantAdded:Connect(onDescendantAdded) |
|
|
| local part = Instance.new("Part") |
| part.Parent = workspaceDescendantRemovingDescendantRemoving fires immediately before the |
| Parent of a descendant of the Instance |
| changes such that the object is no longer a descendant of the Instance. |
| Destroy and Remove |
| change an object's Parent to nil, so calling these on a descendant of an |
| object will therefore cause this event to fire. |
| Since this event fires before the descendant's removal, the Parent of the |
| descendant will be unchanged, i.e., it will still be a descendant at the |
| time of this event firing. If the descendant is also a child of the |
| object, It will also fire before ChildRemoved. There is no similar event |
| called "DescendantRemoved". |
| If a descendant has children, this event fires with the descendant first |
| followed by its descendants. |
| Example |
| The example below should help clarify how DescendantRemoving fires when |
| there are several objects involved. |
|
|
|
|
| Calling Remove on PartA would cause |
| DescendantRemoving to fire on both ModelA and Model, in that |
| order. |
| Setting the Parent of PartA to ModelB |
| would cause DescendantRemoving to fire on ModelA but not Model |
| (as Model would still be an ancestor of PartA). |
| Calling Destroy on ModelA would cause |
| DescendantRemoving to fire multiple times on several objects: |
|
|
| On Model with ModelA, PartA then FireA. |
| On ModelA, with PartA then FireA. |
| On PartA with FireA. |
|
|
|
|
|
|
| Warning |
| This event fires with the descendant object that is being removed. |
| Attempting to set the Parent of the descendant |
| being removed to something else will fail with the following warning: |
| "Something unexpectedly tried to set the parent of X to Y while trying to |
| set the parent of X. Current parent is Z", where X is the removing |
| descendant, Y is the ignored parent setting, and Z is the original parent |
| of X. Below is an example that demonstrates this: |
| workspace.DescendantRemoving:Connect(function(descendant) |
| -- Don't manipulate the parent of descendant in this function! |
| -- This event fires BECAUSE the parent of descendant was manipulated, |
| -- and the change hasn't happened yet, i.e. this function fires before that happens. |
| -- Therefore, it is problematic to change the parent like this: |
| descendant.Parent = game |
| end) |
| local part = Instance.new("Part") |
| part.Parent = workspace |
| part.Parent = nil -- This triggers DescendantRemoving on Workspace: |
| --> Something unexpectedly tried to set the parent of Part to NULL while trying to set the parent of Part. Current parent is Workspace. |
| See also DescendantAdded.Parametersdescendant: InstanceThe Instance that is being removed.Code SamplesThe following example prints the name of any descendant as it is being removed |
| from the Workspace:Instance.DescendantRemovingworkspace.DescendantRemoving:Connect(function(descendant) |
| print(descendant.Name .. " is currently parented to " .. tostring(descendant.Parent)) |
| end) |
| local part = Instance.new("Part") |
| part.Parent = workspace |
| part.Parent = nil |
| --> Part is currently parented to Workspace |
| print(part.Parent) |
| --> nilDestroyingThe Destroying event fires immediately before the Instance or one of its |
| ancestors is destroyed with Instance.Destroy(). |
| The Instance will never be deleted from memory while a connected function |
| is still using it. However, if the function yields at any point, the |
| Instance and its descendants will be parented to nil. |
| When deleting an instance in Studio, such as manually deleting through the |
| Explorer or through a plugin, the instance isn't destroyed. Instead, the |
| parent is set to nil which you can track with |
| Instance.AncestryChanged.Code SamplesThis sample demonstrates how an Instance being destroyed remains in place |
| until the connected function yields.Using the Destroying Eventlocal part = Instance.new("Part", workspace) |
| |
| local function onPartDestroying() |
| print("Before yielding:", part:GetFullName(), #part:GetChildren()) |
| task.wait() |
| print("After yielding:", part:GetFullName(), #part:GetChildren()) |
| end |
| |
| part.Destroying:Connect(onPartDestroying) |
| |
| part:Destroy()childAddedDEPRECATEDDEPRECATEDThis deprecated event is a variant of Instance.ChildAdded which |
| should be used instead.Parameterschild: Instance |