Object
Object is the base class for all classes in the Roblox class hierarchy.
Memory category | Instances |
---|
Member index 6
History | Member | |
---|---|---|
647 | ClassName: string | |
647 | className: string | |
647 | GetPropertyChangedSignal(property: string): RBXScriptSignal | |
647 | IsA(className: string): bool | |
650 | isA(className: string): bool | |
647 | Changed(property: string) |
Description
Object is the base class for all classes in the Roblox class hierarchy. Every other class that the Roblox engine defines inherits all of the members of Object. It is not possible to directly create Object.
History 9
Members 6
Changed
Parameters (1) | |
---|---|
property | string |
This event fires immediately after an object property is changed and it
works with most use cases (see limitations below). The new value of a
changed property is not passed in as a parameter, so it must be
accessed by using object[property]
. For example:
object.Changed:Connect(function(property)
print("The new property's value is", object[property])
end)
If you are only interested in listening to the change of one specific property, consider using the GetPropertyChangedSignal() method instead.
For ValueBase objects such as IntValue and
StringValue, this event only fires when the object's Value
property changes. To detect other changes in ValueBase objects,
use GetPropertyChangedSignal()
instead.
Limitations
This event does not fire for physics-related changes, such as when the CFrame, AssemblyLinearVelocity, AssemblyAngularVelocity, Position, or Orientation properties of a BasePart change due to gravity. To detect changes in these properties, consider using a physics-based event like RunService.PreSimulation.
Additionally, this event may not fire on every modification of properties that change very frequently, and/or it may not fire for such properties at all. It's recommended that you carefully test for property changes that impact game logic.
Thread safety | Unsafe |
---|
ClassName
Type | Default | |
---|---|---|
string |
A read-only string representing the class this Object belongs to.
This property can be used with various other functions that are used to identify objects by type, such as Object:IsA() or Instance:FindFirstChildOfClass().
Note this property is read only and cannot be altered by scripts. Developers wishing to change an object's class will instead have to create a new Object.
Unlike Object:IsA(), ClassName can be used to check if an object belongs to a specific class ignoring class inheritance. For example:
for _, child in workspace:GetChildren() do
if child.ClassName == "Part" then
print("Found a Part")
-- will find Parts in model, but NOT TrussParts, WedgeParts, etc
end
end
Thread safety | ReadSafe |
---|---|
Category | Data |
Loaded/Saved | false |
GetPropertyChangedSignal
Parameters (1) | ||
---|---|---|
property | string | |
Returns (1) | ||
RBXScriptSignal |
This method returns an event that behaves exactly like the Changed event, except that it 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.
ValueBase objects, such as IntValue and
StringValue, use a modified Changed event
that fires with the contents of their Value
property. As such, this
method provides a way to detect changes in other properties of those
objects.
Note that this event will not pass any arguments to a connected function, so the value of the changed property must be read directly within a script.
Limitations
The event returned by this method does not fire for physics-related changes, such as when the CFrame, AssemblyLinearVelocity, AssemblyAngularVelocity, Position, or Orientation properties of a BasePart change due to gravity. To detect changes in these properties, consider using a physics-based event like RunService.PreSimulation.
Additionally, the returned event may not fire on every modification of properties that change very frequently, and/or it may not fire for such properties at all. It's recommended that you carefully test for property changes that impact game logic.
Thread safety | Unsafe |
---|
History 1
IsA
Parameters (1) | ||
---|---|---|
className | string | |
Returns (1) | ||
bool |
IsA returns true if the object'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:
1 2 3 4 5 6 7 8 9 10 11 |
|
Since all classes inherit from Object, calling
object:IsA("Object")
will always return true.
Thread safety | Safe |
---|
className
Type | Default | |
---|---|---|
string |
Thread safety | ReadSafe |
---|---|
Category | Data |
Loaded/Saved | false |
isA
Parameters (1) | ||
---|---|---|
className | string | |
Returns (1) | ||
bool |
Thread safety | Unsafe |
---|