#Instances and parts
Everything in a place is an instance: parts, models, lights, sounds, scripts, GUI elements. This page covers making and finding instances, then the properties of each class.
#Creating and destroying
| Call | Description |
|---|
Instance.new(className) | Makes the object. Parts appear in the workspace immediately. Instance.new(class, parent) works but is easy to misuse, because every property you set afterwards is replicated one at a time. |
Instance.Create(className, props) | Studz addition. Makes the object, sets the properties from the table, and sets Parent last. If a property is invalid, the half-made object is removed and the error is raised. |
inst:Clone() | Copies the object and everything below it, with the same name, next to the original. |
inst:DestroyAfter(seconds) | Studz addition. Destroy after a delay, without blocking the script. |
inst:Destroy() | Removes the object and everything below it, and forgets their tags, attributes and listeners. |
inst:ClearAllChildren() | Destroys every child. A workspace keeps its scripts. |
inst.Parent = nil | Also destroys the object. Studz has no limbo, so an object with no parent cannot be put back. |
local coin = Instance.Create("Part", {
Name = "Coin",
Position = Vector3.new(0, 5, 0),
Size = Vector3.new(1.5, 0.4, 1.5),
Color = "gold",
Anchored = true,
Parent = workspace,
})
#Available classes
| Group | Classes |
|---|
| World | Part, Model, Folder |
| Characters | Humanoid (a rig, or the Humanoid of one: see Rigs) |
| Behaviour | ClickDetector, Script, LocalScript, ModuleScript |
| Effects | PointLight, Decal, Sound |
| Joints | WeldConstraint, Weld (see Welds) |
| Values | IntValue, NumberValue, StringValue, BoolValue, Vector3Value |
| Messaging | RemoteEvent, RemoteFunction, BindableEvent |
| GUI | ScreenGui, TextLabel, TextButton, Frame |
A class name Studz does not know, and that is not a typo, makes a plain Part with a warning.
#Finding instances
#Children and descendants
| Member | Returns | Description |
|---|
inst.Child | Instance or nil | Direct child lookup by name (workspace.Baseplate, part.Weld, character.Humanoid). A real property of the object wins over a child of the same name. On containers (workspace, models, services) a missing name gives nil. On parts and other checked objects it raises an error. |
inst:FindChild(name) | Instance or nil | Child by name. |
inst:GetChild(name) | Instance | Studz addition. Child by name, or an error that names the object and lists its children. Use it where a missing child is a bug. |
inst:FindChildOfClass(class) | Instance or nil | First child that is that class or a subclass. |
inst:AwaitChild(name, [timeout]) | Instance or nil | Yields until the child exists. Returns nil after timeout (default 5 s). |
inst:Children() | table | Direct children. |
inst:Descendants() | table | Every object below. |
workspace:GetPartBoundsInRadius(position, radius) | table | Every object within radius studs of position. |
#Ancestors and identity
| Member | Description |
|---|
inst.Name | Display name. |
inst.ClassName | Class, read-only. |
inst.Parent | The parent: workspace, a model, a folder or a part. |
inst:FindAncestor(name) | Search upward by name. inst:FindAncestorOfClass(class) searches upward by class. |
inst:IsA(class) | Whether the object is that class or a subclass. |
inst:IsDescendantOf(ancestor) | Ancestry check. |
inst:FullName() | Dot path, such as Workspace.ObstacleCourse.LavaPart. |
Tags and attributes let you mark objects without extra instances.
| Member | Description |
|---|
inst:AddTag(tag), :RemoveTag(tag), :HasTag(tag), :GetTags() | Manage tags. |
CollectionService:GetTagged(tag) | Every object with the tag. |
inst:SetAttribute(name, value), :GetAttribute(name), :GetAttributes() | Store values on an object. |
Tags and attributes live on the side that set them. They are not replicated to other machines, and they are forgotten when the object is destroyed.
#Parts
A Part is a physical block, ball, cylinder or wedge.
#Appearance and shape
| Property | Type | Description |
|---|
Name | string | Display name. |
Size | Vector3 | Dimensions. Clamped to at least 0.1. |
Shape | string | "Block", "Ball", "Cylinder" or "Wedge". |
Color | Color3 | Surface tint. A colour name such as "gold" or a hex string is also accepted. |
Material | string | "Plastic", "Neon", "Wood", "Metal", "Slate", "Foil" and others. |
Transparency | number | 0 is solid, 1 is invisible. |
#Position and orientation
| Property | Type | Description |
|---|
CFrame | CFrame | World transform. |
Position | Vector3 | World position. |
Orientation (also Rotation) | Vector3 | Euler angles in degrees. |
Setting CFrame or Position on a player's character or its HumanoidRootPart teleports the character.
#Physics
| Property | Type | Description |
|---|
Anchored | boolean | true freezes the part. false lets physics move it. |
CanCollide | boolean | Whether other things bump into it. |
Friction | number | 0 to 2. |
Elasticity | number | Bounciness, 0 to 1. |
LinearVelocity | Vector3 | Velocity in studs per second (unanchored parts). |
AngularVelocity | Vector3 | Angular velocity. |
SurfaceVelocity | Vector3 | Surface velocity. A part with this set works as a conveyor. |
#Part methods
| Method | Description |
|---|
part:ApplyImpulse(v) | Gives an unanchored part an instant push. |
part:ApplyForce(v) | Applies a force to an unanchored part. |
part:Spin(degreesPerSecond, [axis]) | Rotates the part every frame. Returns a connection: :Off() stops it. |
part:TweenTo(goals, seconds, [style], [direction]) | Animates properties. See World, tweens and effects. |
part:WeldTo(other) | Studz addition. Holds the part where it is now, relative to other (a part or a limb of a player's character), and returns the WeldConstraint it made. See Welds. |
part:BreakWelds() | Destroys every weld that joins the part. Returns how many were broken. |
#Welds
A weld keeps one part in place relative to another. WeldConstraint and Weld are objects you make with Instance.new (or Instance.Create). Parent them anywhere, usually inside Part1.
| Member | Type | Description |
|---|
Part0 | part, limb or nil | What Part1 follows. It may be a limb of a player's character (character.RightArm, character.HumanoidRootPart): the weld then follows that limb, including any pose a script gave it (see Limbs). |
Part1 | part or nil | The part that is held. It must be a part. |
C0, C1 | CFrame | Where the join sits on each part. Part1 is held at Part0 * C0 * C1:Inverse(). A WeldConstraint ignores what you set: it records the offset the two parts have at the moment both Part0 and Part1 are set. |
Enabled | boolean | A disabled weld holds nothing. Enabling a WeldConstraint records the offset again. |
-- Hold a flag on top of a crate. It stays 3 studs above it however the crate moves.
local crate, flag = workspace.Crate, workspace.Flag
local weld = Instance.new("WeldConstraint")
weld.Part0 = crate
weld.Part1 = flag
weld.Parent = flag
-- The same in one call:
flag:WeldTo(crate)
-- A Weld places Part1 by C0 and C1 instead:
local hinge = Instance.new("Weld")
hinge.Part0 = crate
hinge.Part1 = flag
hinge.C0 = CFrame.new(0, 3, 0) * CFrame.Angles(0, math.rad(45), 0)
How welds behave:
- They are held every step, after physics, on the server. A part welded to a rolling ball, to a platform a script moves, or to another welded part keeps its place. Chains work; welds that form a circle are ignored.
- A held part is anchored while the weld holds it, so physics does not fight the weld (a part that was unanchored falls again when the weld goes). It stays solid: its collision moves with it.
- A part is held by one weld at a time. If two welds hold it, the first one in the place wins.
- A
WeldConstraint made between parts already in place moves nothing. A Weld moves Part1 to where its C0 and C1 say on the next step. - A
LocalScript cannot weld. Welds are made and held by the server, and the result is replicated. - A weld to a player's limb follows the player's position, the way they face and any pose a script gave the limb. It does not follow the built-in walk animation or a clip a script plays, which each client draws by itself.
- Welds made by a script exist while the game runs. They are not saved with the place. Weld parts in Polycarbonate with the Weld tool or the
Weld to property: those parts also follow now when a script moves what they are welded to. Clone copies the welds inside a model and joins the copies to each other.
#Models
| Method | Description |
|---|
model:PivotTo(cf) | Moves the whole model. |
model:SetPrimaryPartCFrame(cf) | Roblox-compatible equivalent. |
model:MoveTo(pos) | Moves the model to a position. |
#Other classes
#PointLight
| Property | Description |
|---|
Brightness, Range, Angle | Intensity, reach in studs, cone angle. |
Enabled | Turn the light on and off. |
#Value objects
IntValue, NumberValue, StringValue, BoolValue and Vector3Value hold one value.
| Member | Description |
|---|
.Value | The stored value. |
.Changed:On(function(newValue) end) | Fires with the new value. |
#ClickDetector
| Member | Description |
|---|
MaxActivationDistance | How far away a player can click. Default 32. |
MouseClick:On(function(player) end) | Fires when a player clicks the part. |
For most scripts part.Clicked is simpler, because it creates the detector for you.
#Decal
| Property | Description |
|---|
Texture | The picture, such as decal/123 for a Creator Store decal. |
Face | Which face of the part it covers. |
Color, Transparency | Tint and transparency. |
#Sound
| Member | Description |
|---|
SoundId | The clip: a built-in name or sound/<id> for an upload. |
Volume, Speed, Loop | Playback settings. |
Playing | Whether it is playing. Set it to true to play and false to stop. |
MaxDistance | How far away it can be heard. |
For one-off effects use Sound.play instead of a Sound object: see World, tweens and effects.
A sound inside a part is positional: it gets quieter with distance. A sound in the Workspace plays everywhere.
#GUI objects
TextLabel, TextButton and Frame make on-screen elements. Created in a server script they appear for everyone. Created in a LocalScript they appear for that player only.
| Property | Description |
|---|
Text, TextColor, TextSize, Font | The text and how it looks. |
TextTransparency, ShadowTransparency, ShadowColor | Text fading and shadow. |
Position, Size | UDim2 values. |
AnchorPoint | Vector2. |
BackgroundColor, BackgroundTransparency | Fill. |
BorderColor, BorderWidth, CornerRadius | Border and rounding. |
Visible, ZIndex | Show or hide, and stacking order. |
A button's click signal is Clicked. It is a normal signal, so On returns a connection. Destroy() removes an element. GuiService:ClearAll() removes every script-made element. At most 500 GUI elements can exist at once.
local label = Instance.Create("TextLabel", {
Text = "Welcome!",
Position = UDim2.new(0.5, 0, 0.1, 0),
AnchorPoint = Vector2.new(0.5, 0),
TextSize = 28,
})
For quick messages, the ui helper is shorter: see Globals and services.