mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-10-23 14:01:37 +00:00
2449 lines
78 KiB
YAML
2449 lines
78 KiB
YAML
# This file is automatically generated. Please don't edit it manually.
|
||
# To submit a bug report on the content, see
|
||
# https://devforum.roblox.com/c/bug-reports/documentation-issues/72
|
||
|
||
name: Instance
|
||
type: class
|
||
memory_category: Instances
|
||
summary: |
|
||
`Instance` is the base class for all classes in the Roblox class hierarchy
|
||
which can be part of the `Class.DataModel` tree.
|
||
description: |
|
||
`Instance` is the base class for all classes in the Roblox class hierarchy
|
||
which can be part of the `Class.DataModel` tree.
|
||
|
||
It is not possible to directly create root `Instance` objects, but the special
|
||
`Datatype.Instance.new()` constructor creates objects via code, taking the
|
||
name of the class as a parameter and returning the created object.
|
||
code_samples: []
|
||
inherits:
|
||
- Object
|
||
descendants:
|
||
- AccessoryDescription
|
||
- Accoutrement
|
||
- AdPortal
|
||
- AdService
|
||
- AdvancedDragger
|
||
- AnalyticsService
|
||
- Animation
|
||
- AnimationClip
|
||
- AnimationClipProvider
|
||
- AnimationController
|
||
- AnimationFromVideoCreatorService
|
||
- AnimationRigData
|
||
- AnimationTrack
|
||
- Animator
|
||
- AssetDeliveryProxy
|
||
- AssetPatchSettings
|
||
- AssetService
|
||
- Atmosphere
|
||
- Attachment
|
||
- AudioAnalyzer
|
||
- AudioChannelMixer
|
||
- AudioChannelSplitter
|
||
- AudioChorus
|
||
- AudioCompressor
|
||
- AudioDeviceInput
|
||
- AudioDeviceOutput
|
||
- AudioDistortion
|
||
- AudioEcho
|
||
- AudioEmitter
|
||
- AudioEqualizer
|
||
- AudioFader
|
||
- AudioFilter
|
||
- AudioFlanger
|
||
- AudioGate
|
||
- AudioLimiter
|
||
- AudioListener
|
||
- AudioPitchShifter
|
||
- AudioPlayer
|
||
- AudioRecorder
|
||
- AudioReverb
|
||
- AudioSearchParams
|
||
- AudioSpeechToText
|
||
- AudioTextToSpeech
|
||
- AudioTremolo
|
||
- AvatarCreationService
|
||
- AvatarEditorService
|
||
- Backpack
|
||
- BadgeService
|
||
- BasePlayerGui
|
||
- BaseRemoteEvent
|
||
- BaseWrap
|
||
- Beam
|
||
- BindableEvent
|
||
- BindableFunction
|
||
- BodyMover
|
||
- BodyPartDescription
|
||
- BrowserService
|
||
- CacheableContentProvider
|
||
- CaptureService
|
||
- ChangeHistoryService
|
||
- CharacterAppearance
|
||
- Chat
|
||
- ClickDetector
|
||
- Clouds
|
||
- CollectionService
|
||
- CommerceService
|
||
- CompositeValueCurve
|
||
- ConfigService
|
||
- Configuration
|
||
- Constraint
|
||
- ContentProvider
|
||
- ContextActionService
|
||
- Controller
|
||
- ControllerBase
|
||
- ControllerManager
|
||
- ControllerService
|
||
- CookiesService
|
||
- CustomEvent
|
||
- CustomEventReceiver
|
||
- CustomLog
|
||
- DataModelMesh
|
||
- DataModelSession
|
||
- DataStoreGetOptions
|
||
- DataStoreIncrementOptions
|
||
- DataStoreInfo
|
||
- DataStoreKey
|
||
- DataStoreKeyInfo
|
||
- DataStoreObjectVersionInfo
|
||
- DataStoreOptions
|
||
- DataStoreService
|
||
- DataStoreSetOptions
|
||
- Debris
|
||
- DebugSettings
|
||
- Dialog
|
||
- DialogChoice
|
||
- Dragger
|
||
- EncodingService
|
||
- EulerRotationCurve
|
||
- ExperienceInviteOptions
|
||
- ExperienceNotificationService
|
||
- Explosion
|
||
- FaceControls
|
||
- FaceInstance
|
||
- Feature
|
||
- FeatureRestrictionManager
|
||
- Fire
|
||
- FlagStandService
|
||
- FloatCurve
|
||
- Folder
|
||
- ForceField
|
||
- FriendService
|
||
- FunctionalTest
|
||
- GamePassService
|
||
- GameSettings
|
||
- GamepadService
|
||
- GenerationService
|
||
- GenericChallengeService
|
||
- Geometry
|
||
- GeometryService
|
||
- GlobalDataStore
|
||
- GroupService
|
||
- GuiBase
|
||
- GuiService
|
||
- GuidRegistryService
|
||
- HandRigDescription
|
||
- HapticEffect
|
||
- HapticService
|
||
- HeapProfilerService
|
||
- HeightmapImporterService
|
||
- HiddenSurfaceRemovalAsset
|
||
- Highlight
|
||
- Hopper
|
||
- HttpRbxApiService
|
||
- HttpService
|
||
- Humanoid
|
||
- HumanoidDescription
|
||
- HumanoidRigDescription
|
||
- IKControl
|
||
- ILegacyStudioBridge
|
||
- IncrementalPatchBuilder
|
||
- InputObject
|
||
- InsertService
|
||
- JointInstance
|
||
- JointsService
|
||
- KeyboardService
|
||
- Keyframe
|
||
- KeyframeMarker
|
||
- KeyframeSequenceProvider
|
||
- Light
|
||
- Lighting
|
||
- LocalizationService
|
||
- LocalizationTable
|
||
- LogService
|
||
- LoginService
|
||
- LuaSettings
|
||
- LuaSourceContainer
|
||
- LuaWebService
|
||
- MLService
|
||
- MarkerCurve
|
||
- MarketplaceService
|
||
- MatchmakingService
|
||
- MaterialService
|
||
- MaterialVariant
|
||
- MemStorageConnection
|
||
- MemStorageService
|
||
- MemoryStoreHashMap
|
||
- MemoryStoreQueue
|
||
- MemoryStoreService
|
||
- MemoryStoreSortedMap
|
||
- Message
|
||
- MessagingService
|
||
- MicroProfilerService
|
||
- ModerationService
|
||
- Mouse
|
||
- MouseService
|
||
- MultipleDocumentInterfaceInstance
|
||
- NetworkSettings
|
||
- NoCollisionConstraint
|
||
- NotificationService
|
||
- OpenCloudApiV1
|
||
- OpenCloudService
|
||
- PVInstance
|
||
- PackageLink
|
||
- PackageService
|
||
- Pages
|
||
- PartOperationAsset
|
||
- ParticleEmitter
|
||
- PatchMapping
|
||
- Path
|
||
- PathfindingLink
|
||
- PathfindingModifier
|
||
- PathfindingService
|
||
- PermissionsService
|
||
- PhysicsService
|
||
- PhysicsSettings
|
||
- Player
|
||
- PlayerScripts
|
||
- PlayerViewService
|
||
- Players
|
||
- Plugin
|
||
- PluginAction
|
||
- PluginCapabilities
|
||
- PluginDebugService
|
||
- PluginDragEvent
|
||
- PluginGuiService
|
||
- PluginManager
|
||
- PluginManagerInterface
|
||
- PluginMenu
|
||
- PluginToolbar
|
||
- PluginToolbarButton
|
||
- PointsService
|
||
- PolicyService
|
||
- PoseBase
|
||
- PostEffect
|
||
- ProcessInstancePhysicsService
|
||
- ProximityPrompt
|
||
- ProximityPromptService
|
||
- PublishService
|
||
- ReflectionService
|
||
- RemoteDebuggerServer
|
||
- RemoteFunction
|
||
- RenderingTest
|
||
- ReplicatedFirst
|
||
- ReplicatedStorage
|
||
- RotationCurve
|
||
- RunService
|
||
- ScreenshotHud
|
||
- ScriptBuilder
|
||
- ScriptContext
|
||
- ScriptProfilerService
|
||
- ScriptService
|
||
- Selection
|
||
- SensorBase
|
||
- SerializationService
|
||
- ServerScriptService
|
||
- ServerStorage
|
||
- ServiceProvider
|
||
- SessionCheckService
|
||
- SharedTableRegistry
|
||
- Sky
|
||
- Smoke
|
||
- SmoothVoxelsUpgraderService
|
||
- SocialService
|
||
- Sound
|
||
- SoundEffect
|
||
- SoundGroup
|
||
- SoundService
|
||
- Sparkles
|
||
- SpawnerService
|
||
- StandalonePluginScripts
|
||
- StarterGear
|
||
- StarterPack
|
||
- StarterPlayer
|
||
- StarterPlayerScripts
|
||
- Stats
|
||
- StatsItem
|
||
- SurfaceAppearance
|
||
- TaskScheduler
|
||
- Team
|
||
- TeamCreateData
|
||
- Teams
|
||
- TeleportAsyncResult
|
||
- TeleportOptions
|
||
- TeleportService
|
||
- TerrainDetail
|
||
- TerrainRegion
|
||
- TestService
|
||
- TextBoxService
|
||
- TextChannel
|
||
- TextChatCommand
|
||
- TextChatConfigurations
|
||
- TextChatMessage
|
||
- TextChatMessageProperties
|
||
- TextChatService
|
||
- TextFilterResult
|
||
- TextFilterTranslatedResult
|
||
- TextGenerator
|
||
- TextService
|
||
- TextSource
|
||
- TimerService
|
||
- TouchInputService
|
||
- TouchTransmitter
|
||
- Trail
|
||
- Translator
|
||
- TweenBase
|
||
- TweenService
|
||
- UGCValidationService
|
||
- UIBase
|
||
- UserGameSettings
|
||
- UserInputService
|
||
- UserService
|
||
- VRService
|
||
- ValueBase
|
||
- ValueCurve
|
||
- Vector3Curve
|
||
- VideoCaptureService
|
||
- VideoPlayer
|
||
- VideoService
|
||
- VirtualUser
|
||
- VisibilityCheckDispatcher
|
||
- Visit
|
||
- VisualizationMode
|
||
- VisualizationModeCategory
|
||
- VisualizationModeService
|
||
- VoiceChatService
|
||
- WeldConstraint
|
||
- Wire
|
||
- WrapTextureTransfer
|
||
- RenderSettings
|
||
- StartupMessageService
|
||
- StopWatchReporter
|
||
- VirtualInputManager
|
||
- PatchBundlerFileWatch
|
||
- CreatorStoreService
|
||
- InputAction
|
||
- InputBinding
|
||
- InputContext
|
||
- ClusterPacketCache
|
||
- ConfigureServerService
|
||
- NetworkMarker
|
||
- NetworkPeer
|
||
- NetworkReplicator
|
||
- RecommendationService
|
||
- CoreScriptDebuggingManagerHelper
|
||
- DraftsService
|
||
- DraggerService
|
||
- File
|
||
- InstanceFileSyncService
|
||
- PlacesService
|
||
- PluginManagementService
|
||
- ReflectionMetadata
|
||
- ReflectionMetadataCallbacks
|
||
- ReflectionMetadataClasses
|
||
- ReflectionMetadataEnums
|
||
- ReflectionMetadataEvents
|
||
- ReflectionMetadataFunctions
|
||
- ReflectionMetadataItem
|
||
- ReflectionMetadataProperties
|
||
- ReflectionMetadataYieldFunctions
|
||
- ScriptDocument
|
||
- ScriptEditorService
|
||
- SelectionHighlightManager
|
||
- Studio
|
||
- StudioTestService
|
||
- StudioTheme
|
||
- TeamCreateService
|
||
- VRStatusService
|
||
- StudioService
|
||
- StyleBase
|
||
- StyleDerive
|
||
- StyleLink
|
||
- Annotation
|
||
- ServiceVisibilityService
|
||
- GetTextBoundsParams
|
||
tags:
|
||
- NotCreatable
|
||
- NotBrowsable
|
||
deprecation_message: ''
|
||
properties:
|
||
- name: Instance.Archivable
|
||
summary: |
|
||
Determines if an `Class.Instance` and its descendants can be cloned using
|
||
`Class.Instance:Clone()`, and can be saved/published.
|
||
description: |
|
||
This property determines whether the instance should be included when the
|
||
experience is published or saved, or when `Class.Instance:Clone()|Clone()`
|
||
is called on one of the instance's ancestors. Calling
|
||
`Class.Instance:Clone()|Clone()` directly on an instance will return `nil`
|
||
if that instance is **not** `Class.Instance.Archivable|Archivable`.
|
||
|
||
Copying an object in Studio using the **Duplicate** or **Copy**/**Paste**
|
||
options will ignore its own `Class.Instance.Archivable|Archivable`
|
||
property and set `Class.Instance.Archivable|Archivable` to `true` for the
|
||
copy.
|
||
|
||
```
|
||
local part = Instance.new("Part")
|
||
print(part:Clone()) --> Part
|
||
part.Archivable = false
|
||
print(part:Clone()) --> nil
|
||
```
|
||
code_samples: []
|
||
type: boolean
|
||
tags: []
|
||
deprecation_message: ''
|
||
security:
|
||
read: None
|
||
write: None
|
||
thread_safety: ReadSafe
|
||
category: Behavior
|
||
serialization:
|
||
can_load: false
|
||
can_save: false
|
||
capabilities: []
|
||
- name: Instance.archivable
|
||
summary: ''
|
||
description: ''
|
||
code_samples: []
|
||
type: boolean
|
||
tags:
|
||
- Hidden
|
||
- NotReplicated
|
||
- Deprecated
|
||
deprecation_message: |
|
||
This deprecated property is a variant of `Class.Instance.Archivable` which
|
||
should be used instead.
|
||
security:
|
||
read: None
|
||
write: None
|
||
thread_safety: ReadSafe
|
||
category: Behavior
|
||
serialization:
|
||
can_load: true
|
||
can_save: false
|
||
capabilities: []
|
||
- name: Instance.Capabilities
|
||
summary: |
|
||
The set of capabilities allowed to be used for scripts inside this
|
||
container.
|
||
description: |
|
||
The set of capabilities allowed to be used for scripts inside this
|
||
instance. For the capabilities to take effect, `Class.Instance.Sandboxed`
|
||
property must be enabled.
|
||
|
||
This property is used by an experimental feature. See
|
||
[script capabilities](../../../scripting/capabilities.md) for further
|
||
details.
|
||
code_samples: []
|
||
type: SecurityCapabilities
|
||
tags: []
|
||
deprecation_message: ''
|
||
security:
|
||
read: None
|
||
write: None
|
||
thread_safety: ReadSafe
|
||
category: Permissions
|
||
serialization:
|
||
can_load: true
|
||
can_save: true
|
||
capabilities:
|
||
- CapabilityControl
|
||
- name: Instance.Name
|
||
summary: |
|
||
A non-unique identifier of the `Class.Instance`.
|
||
description: |
|
||
A non-unique identifier of the `Class.Instance`. Names are used to keep
|
||
the object hierarchy organized, along with allowing scripts to access
|
||
specific objects. The name of an instance cannot exceed 100 characters in
|
||
size.
|
||
|
||
The name of an object is often used to access the object through the data
|
||
model hierarchy using the following methods:
|
||
|
||
```
|
||
local Workspace = game:GetService("Workspace")
|
||
|
||
local baseplate = Workspace.Baseplate
|
||
local baseplate = Workspace["Baseplate"]
|
||
local baseplate = Workspace:FindFirstChild("BasePlate")
|
||
```
|
||
|
||
In order to make an object accessible using the dot operator (`.`), its
|
||
name must start with an underscore or letter, and the rest of the name can
|
||
only contain letters, numbers, or underscores (no other special
|
||
characters). If an object's name does not follow this syntax, it will not
|
||
be accessible using the dot operator and Luau will not interpret its name
|
||
as an identifier.
|
||
|
||
If more than one object with the same name are siblings, any attempt to
|
||
index an object by that name will return only one of the objects, similar
|
||
to `Class.Instance:FindFirstChild()`, but not always the desired object.
|
||
If a specific object needs to be accessed through code, it's recommended
|
||
to give it a unique name or guarantee that none of its siblings share the
|
||
same name.
|
||
|
||
See also `Class.Instance:GetFullName()` to obtain a full name including
|
||
the object's hierarchy.
|
||
code_samples: []
|
||
type: string
|
||
tags: []
|
||
deprecation_message: ''
|
||
security:
|
||
read: None
|
||
write: None
|
||
thread_safety: ReadSafe
|
||
category: Data
|
||
serialization:
|
||
can_load: true
|
||
can_save: true
|
||
capabilities: []
|
||
- name: Instance.Parent
|
||
summary: |
|
||
Determines the hierarchical parent of the `Class.Instance`.
|
||
description: |
|
||
The `Parent` property determines the hierarchical parent of the
|
||
`Class.Instance`. The following terminology is commonly used when talking
|
||
about how this property is set:
|
||
|
||
- An object is a **child** of, or is **parented to**, another object when
|
||
its `Parent` is set to that object.
|
||
|
||
- The **descendants** of an `Class.Instance` are the children of that
|
||
object, plus the descendants of the children as well.
|
||
|
||
- The **ancestors** of an `Class.Instance` are all the objects that the
|
||
instance is a descendant of.
|
||
|
||
It is from the `Parent` property that many other API members get their
|
||
name, such as `Class.Instance:GetChildren()|GetChildren()` and
|
||
`Class.Instance:FindFirstChild()|FindFirstChild()`. This property is also
|
||
used to manage whether an object exists in the experience or needs to be
|
||
removed. As long as an object's parent is in the `Class.DataModel`, is
|
||
stored in a variable, or is referenced by another object's property, the
|
||
object remains in the experience; otherwise, the object will automatically
|
||
be removed.
|
||
|
||
Calling `Class.Instance:Destroy()|Destroy()` will set the `Parent` of an
|
||
`Class.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.
|
||
|
||
Newly created objects using `Datatype.Instance.new()` will not have a
|
||
parent, and usually will not be visible or function until one is set.
|
||
|
||
##### Object Replication
|
||
|
||
An object created by the server will not replicate to clients until it is
|
||
parented to some object that is replicated. When creating an object and
|
||
setting many properties, it's recommended to set the `Parent` property
|
||
**last**. This ensures the object replicates once, instead of replicating
|
||
many property changes.
|
||
|
||
```lua
|
||
local Workspace = game:GetService("Workspace")
|
||
|
||
-- Set new instance's parent last (recommended)
|
||
local part = Instance.new("Part")
|
||
part.Position = Vector3.new(0, 10, 0)
|
||
part.Parent = Workspace
|
||
```
|
||
|
||
However, if parenting parts to a `Class.Model` whose parent hasn't been
|
||
set yet, parenting each part to that model is acceptable since the model
|
||
would not have replicated.
|
||
code_samples: []
|
||
type: Instance
|
||
tags:
|
||
- NotReplicated
|
||
deprecation_message: ''
|
||
security:
|
||
read: None
|
||
write: None
|
||
thread_safety: ReadSafe
|
||
category: Data
|
||
serialization:
|
||
can_load: true
|
||
can_save: false
|
||
capabilities: []
|
||
- name: Instance.PredictionMode
|
||
summary: ''
|
||
description: ''
|
||
code_samples: []
|
||
type: PredictionMode
|
||
tags:
|
||
- ReadOnly
|
||
- NotReplicated
|
||
- NotScriptable
|
||
deprecation_message: ''
|
||
security:
|
||
read: None
|
||
write: None
|
||
thread_safety: ReadSafe
|
||
category: Data
|
||
serialization:
|
||
can_load: false
|
||
can_save: false
|
||
capabilities: []
|
||
- name: Instance.RobloxLocked
|
||
summary: |
|
||
A deprecated property that used to protect `Class.CoreGui` objects.
|
||
description: |
|
||
This property used to protect objects in the `Class.CoreGui` service from
|
||
being altered by users in an unauthorized manner. It has been deprecated
|
||
and does not do anything.
|
||
code_samples: []
|
||
type: boolean
|
||
tags:
|
||
- Hidden
|
||
deprecation_message: |
|
||
This property is deprecated and does not do anything.
|
||
security:
|
||
read: PluginSecurity
|
||
write: PluginSecurity
|
||
thread_safety: ReadSafe
|
||
category: Data
|
||
serialization:
|
||
can_load: false
|
||
can_save: false
|
||
capabilities: []
|
||
- name: Instance.Sandboxed
|
||
summary: |
|
||
Turns the instance to be a sandboxed container.
|
||
description: |
|
||
Turns the instance to be a **sandboxed container**, an experimental
|
||
feature which limits the actions that scripts inside a particular
|
||
container can perform. See
|
||
[script capabilities](../../../scripting/capabilities.md) for further
|
||
details.
|
||
code_samples: []
|
||
type: boolean
|
||
tags:
|
||
- NotReplicated
|
||
deprecation_message: ''
|
||
security:
|
||
read: None
|
||
write: None
|
||
thread_safety: ReadSafe
|
||
category: Permissions
|
||
serialization:
|
||
can_load: false
|
||
can_save: false
|
||
capabilities:
|
||
- CapabilityControl
|
||
- name: Instance.UniqueId
|
||
summary: |
|
||
A unique identifier for the instance.
|
||
description: |
|
||
A unique identifier for the instance, distinct from `Class.Instance.Name`
|
||
which is not necessarily unique.
|
||
code_samples: []
|
||
type: UniqueId
|
||
tags:
|
||
- NotReplicated
|
||
deprecation_message: ''
|
||
security:
|
||
read: RobloxScriptSecurity
|
||
write: RobloxEngineSecurity
|
||
thread_safety: ReadSafe
|
||
category: Data
|
||
serialization:
|
||
can_load: true
|
||
can_save: true
|
||
capabilities: []
|
||
methods:
|
||
- name: Instance:AddTag
|
||
summary: |
|
||
Applies a tag to the instance.
|
||
description: |
|
||
This 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
|
||
`Class.CollectionService:GetInstanceAddedSignal()` with the given tag.
|
||
|
||
##### Warnings
|
||
|
||
- An instance's tags that were added client-side will be dropped if the
|
||
server later adds or removes a tag on that instance because the server
|
||
replicates all tags together and overwrites previous tags.
|
||
|
||
- When tagging an instance, it is 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 `Class.Instance:RemoveTag()`, calling
|
||
`Class.Instance:Destroy()`, or in a function connected to a signal
|
||
returned by `Class.CollectionService:GetInstanceRemovedSignal()`.
|
||
code_samples: []
|
||
parameters:
|
||
- name: tag
|
||
type: string
|
||
default:
|
||
summary: ''
|
||
returns:
|
||
- type: ()
|
||
summary: ''
|
||
tags: []
|
||
deprecation_message: ''
|
||
security: None
|
||
thread_safety: Unsafe
|
||
capabilities: []
|
||
- name: Instance:children
|
||
summary: |
|
||
Returns an array of the object's children.
|
||
description: |
|
||
The children function returns an array of the object's children.
|
||
code_samples: []
|
||
parameters: []
|
||
returns:
|
||
- type: Instances
|
||
summary: |
|
||
Array of child objects/instances.
|
||
tags:
|
||
- Deprecated
|
||
deprecation_message: |
|
||
This item has been superseded by `Class.Instance:GetChildren()` which
|
||
should be used in all new work.
|
||
security: None
|
||
thread_safety: Unsafe
|
||
capabilities: []
|
||
- name: Instance:ClearAllChildren
|
||
summary: |
|
||
This method destroys all of an instance's children.
|
||
description: |
|
||
This method destroys all of an instance's children and descendants.
|
||
|
||
```
|
||
local part = Instance.new("Part")
|
||
|
||
-- Add some sparkles
|
||
for i = 1, 3 do
|
||
local sparkles = Instance.new("Sparkles")
|
||
sparkles.Parent = part
|
||
|
||
local sc = Instance.new("Sparkles")
|
||
sc.Parent = sparkles
|
||
end
|
||
|
||
print("Children:", #part:GetChildren()) --> Children: 3
|
||
|
||
part:ClearAllChildren()
|
||
|
||
print("Children:", #part:GetChildren()) --> Children: 0
|
||
```
|
||
|
||
If you do not wish to destroy **all** children and descendants, use either
|
||
`Class.Instance:GetChildren()` or `Class.Instance:GetDescendants()` to
|
||
loop through those children/descendants and select what to destroy. For
|
||
example, the following code sample will destroy all
|
||
`Class.BasePart|BaseParts` descending from a `Class.Model`:
|
||
|
||
```
|
||
local Workspace = game:GetService("Workspace")
|
||
|
||
local model = Workspace:FindFirstChild("TestModel")
|
||
|
||
for _, descendant in model:GetDescendants() do
|
||
if descendant:IsA("BasePart") then
|
||
descendant:Destroy()
|
||
end
|
||
end
|
||
```
|
||
code_samples: []
|
||
parameters: []
|
||
returns:
|
||
- type: ()
|
||
summary: ''
|
||
tags: []
|
||
deprecation_message: ''
|
||
security: None
|
||
thread_safety: Unsafe
|
||
capabilities: []
|
||
- name: Instance:Clone
|
||
summary: |
|
||
Create a copy of an instance and all its descendants, ignoring instances
|
||
that are not `Class.Instance.Archivable|Archivable`.
|
||
description: |
|
||
`Clone()` creates a copy of an instance and all of its descendants,
|
||
ignoring all instances that are not
|
||
`Class.Instance.Archivable|Archivable`. The copy of the root instance is
|
||
returned by this method and its `Class.Instance.Parent|Parent` is set to
|
||
`nil`. Note that if the instance itself has
|
||
`Class.Instance.Archivable|Archivable` set to `false`, this method will
|
||
return `nil`.
|
||
|
||
If a reference property such as `Class.ObjectValue.Value` is set in a
|
||
cloned instance, the value of the copy's property depends on the
|
||
original's value:
|
||
|
||
- If a reference property refers to an instance that was **also** cloned,
|
||
the copy will refer to the copy.
|
||
- If a reference property refers to an instance that was **not** cloned,
|
||
the same value is maintained in the copy.
|
||
code_samples:
|
||
- Clone-Example
|
||
parameters: []
|
||
returns:
|
||
- type: Instance
|
||
summary: ''
|
||
tags: []
|
||
deprecation_message: ''
|
||
security: None
|
||
thread_safety: Unsafe
|
||
capabilities:
|
||
- CreateInstances
|
||
- name: Instance:clone
|
||
summary: ''
|
||
description: ''
|
||
code_samples: []
|
||
parameters: []
|
||
returns:
|
||
- type: Instance
|
||
summary: ''
|
||
tags:
|
||
- Deprecated
|
||
deprecation_message: |
|
||
This deprecated function is a variant of `Class.Instance:Clone()` which
|
||
should be used instead.
|
||
security: None
|
||
thread_safety: Unsafe
|
||
capabilities:
|
||
- CreateInstances
|
||
- name: Instance:Destroy
|
||
summary: |
|
||
Sets the `Class.Instance.Parent` property to `nil`, locks the
|
||
`Class.Instance.Parent` property, disconnects all connections, and calls
|
||
`Destroy()` on all children.
|
||
description: |
|
||
Sets the `Class.Instance.Parent` property to `nil`, locks the
|
||
`Class.Instance.Parent` property, disconnects all connections, and calls
|
||
`Destroy()` on all children. This method 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 which can lead to serious performance
|
||
issues over time.
|
||
|
||
As a best practice 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.
|
||
|
||
```lua
|
||
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 `Class.Instance` has been destroyed by this method, it cannot be
|
||
reused because the `Class.Instance.Parent` property is locked. To
|
||
**temporarily** remove an object instead of destroying it, set
|
||
`Class.Instance.Parent|Parent` to `nil`. For example:
|
||
|
||
```
|
||
local Workspace = game:GetService("Workspace")
|
||
|
||
object.Parent = nil
|
||
task.wait(2)
|
||
object.Parent = Workspace
|
||
```
|
||
|
||
To destroy an object after a set amount of time, use
|
||
`Class.Debris:AddItem()`.
|
||
code_samples:
|
||
- Instance-Destroy1
|
||
parameters: []
|
||
returns:
|
||
- type: ()
|
||
summary: ''
|
||
tags: []
|
||
deprecation_message: ''
|
||
security: None
|
||
thread_safety: Unsafe
|
||
capabilities: []
|
||
- name: Instance:destroy
|
||
summary: ''
|
||
description: ''
|
||
code_samples: []
|
||
parameters: []
|
||
returns:
|
||
- type: ()
|
||
summary: ''
|
||
tags:
|
||
- Deprecated
|
||
deprecation_message: |
|
||
This deprecated function is a variant of `Class.Instance:Destroy()` which
|
||
should be used instead.
|
||
security: None
|
||
thread_safety: Unsafe
|
||
capabilities: []
|
||
- name: Instance:FindFirstAncestor
|
||
summary: |
|
||
Returns the first ancestor of the `Class.Instance` whose
|
||
`Class.Instance.Name` is equal to the given name.
|
||
description: |
|
||
Returns the first ancestor of the `Class.Instance` whose
|
||
`Class.Instance.Name` is equal to the given name.
|
||
|
||
This method works upwards, meaning it starts at the instance's immediate
|
||
`Class.Instance.Parent` and works up towards the `Class.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 method that find ancestors of a specific class,
|
||
please see `Class.Instance:FindFirstAncestorOfClass()` and
|
||
`Class.Instance:FindFirstAncestorWhichIsA()`.
|
||
code_samples: []
|
||
parameters:
|
||
- name: name
|
||
type: string
|
||
default:
|
||
summary: |
|
||
The `Class.Instance.Name` to be looked for.
|
||
returns:
|
||
- type: Instance
|
||
summary: |
|
||
The `Class.Instance` found.
|
||
tags: []
|
||
deprecation_message: ''
|
||
security: None
|
||
thread_safety: Safe
|
||
capabilities: []
|
||
- name: Instance:FindFirstAncestorOfClass
|
||
summary: |
|
||
Returns the first ancestor of the `Class.Instance` whose
|
||
`Class.Object.ClassName` is equal to the given className.
|
||
description: |
|
||
Returns the first ancestor of the `Class.Instance` whose
|
||
`Class.Object.ClassName` is equal to the given className.
|
||
|
||
This method works upwards, meaning it starts at the instance's immediate
|
||
`Class.Instance.Parent` and works up towards the `Class.DataModel`. If no
|
||
matching ancestor is found, it returns `nil`.
|
||
|
||
A common use of this method is finding the `Class.Model` a
|
||
`Class.BasePart` belongs to. For example:
|
||
|
||
```
|
||
local model = part:FindFirstAncestorOfClass("Model")
|
||
```
|
||
|
||
This method is a variant of `Class.Instance:FindFirstAncestor()` which
|
||
checks the `Class.Object.ClassName` property rather than
|
||
`Class.Instance.Name`. `Class.Instance:FindFirstAncestorWhichIsA()` also
|
||
exists, using the `Class.Object:IsA()` method instead to respect class
|
||
inheritance.
|
||
code_samples: []
|
||
parameters:
|
||
- name: className
|
||
type: string
|
||
default:
|
||
summary: |
|
||
The `Class.Object.ClassName` to be looked for.
|
||
returns:
|
||
- type: Instance
|
||
summary: |
|
||
The `Class.Instance` found.
|
||
tags: []
|
||
deprecation_message: ''
|
||
security: None
|
||
thread_safety: Safe
|
||
capabilities: []
|
||
- name: Instance:FindFirstAncestorWhichIsA
|
||
summary: |
|
||
Returns the first ancestor of the `Class.Instance` for whom
|
||
`Class.Object:IsA()` returns true for the given className.
|
||
description: |
|
||
Returns the first ancestor of the `Class.Instance` for whom
|
||
`Class.Object:IsA()` returns true for the given className.
|
||
|
||
This method works upwards, meaning it starts at the instance's immediate
|
||
`Class.Instance.Parent` and works up towards the `Class.DataModel`. If no
|
||
matching ancestor is found, it returns `nil`.
|
||
|
||
Unlike `Class.Instance:FindFirstAncestorOfClass()`, this method uses
|
||
`Class.Object: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
|
||
`Class.BasePart` ancestor, regardless of if it is a `Class.WedgePart`,
|
||
`Class.MeshPart` or `Class.Part`.
|
||
|
||
```
|
||
local part = object:FindFirstAncestorWhichIsA("BasePart")
|
||
```
|
||
|
||
See also `Class.Instance:FindFirstAncestor()`.
|
||
code_samples: []
|
||
parameters:
|
||
- name: className
|
||
type: string
|
||
default:
|
||
summary: |
|
||
The `Class.Object.ClassName` to be looked for.
|
||
returns:
|
||
- type: Instance
|
||
summary: |
|
||
The `Class.Instance` found.
|
||
tags: []
|
||
deprecation_message: ''
|
||
security: None
|
||
thread_safety: Safe
|
||
capabilities: []
|
||
- name: Instance:FindFirstChild
|
||
summary: |
|
||
Returns the first child of the `Class.Instance` found with the given name.
|
||
description: |
|
||
Returns the first child of the `Class.Instance` with the given name, or
|
||
`nil` if no such child exists. If the optional `recursive` argument is
|
||
`true`, this method searches all descendants rather than only the
|
||
immediate children of the `Class.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.
|
||
|
||
```lua
|
||
local Workspace = game:GetService("Workspace")
|
||
|
||
-- The following line errors if the part doesn't exist in the workspace
|
||
Workspace.Part.Transparency = 0.5
|
||
```
|
||
|
||
A better approach is to use `FindFirstChild()` to first check for `Part`,
|
||
then use an `if` statement to run code that needs it.
|
||
|
||
```lua
|
||
local Workspace = game:GetService("Workspace")
|
||
|
||
local part = Workspace:FindFirstChild("Part")
|
||
if part then
|
||
part.Transparency = 0.5
|
||
end
|
||
```
|
||
|
||
##### Finding a Child Whose Name Matches a Property
|
||
|
||
Sometimes the `Class.Instance.Name|Name` of an object is the same as that
|
||
of a property of its `Class.Instance.Parent|Parent`. When using the dot
|
||
operator, properties take precedence over children if they share a name.
|
||
|
||
In the following example, a `Class.Folder` called `Color` is added to a
|
||
`Class.Part`, which also has the `Class.Part.Color` property. Notice that
|
||
`part.Color` refers to the `Datatype.Color3` property value, not the child
|
||
`Class.Folder` instance. A benefit of using
|
||
`Class.Instance:FindFirstChild()|FindFirstChild()` is that the
|
||
introduction of new properties does not impose a risk on your code.
|
||
|
||
```lua
|
||
local part = Instance.new("Part")
|
||
local folder = Instance.new("Folder")
|
||
folder.Name = "Color"
|
||
folder.Parent = part
|
||
local c1 = part.Color -- The property
|
||
local c2 = part:FindFirstChild("Color") -- The child folder
|
||
```
|
||
|
||
##### Performance Notes
|
||
|
||
`Class.Instance:FindFirstChild()|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 `Class.RunService.Heartbeat` and `Class.RunService.PreRender`. Instead,
|
||
store the result in a variable, or consider using
|
||
`Class.Instance.ChildAdded|ChildAdded` or
|
||
`Class.Instance:WaitForChild()|WaitForChild()` to detect when a child of a
|
||
given name becomes available.
|
||
code_samples:
|
||
- Instance-FindFirstChild1
|
||
parameters:
|
||
- name: name
|
||
type: string
|
||
default:
|
||
summary: |
|
||
The `Class.Instance.Name` to be searched for.
|
||
- name: recursive
|
||
type: boolean
|
||
default: false
|
||
summary: |
|
||
Whether or not the search should be conducted recursively.
|
||
returns:
|
||
- type: Instance
|
||
summary: |
|
||
The `Class.Instance` found.
|
||
tags: []
|
||
deprecation_message: ''
|
||
security: None
|
||
thread_safety: Safe
|
||
capabilities: []
|
||
- name: Instance:findFirstChild
|
||
summary: ''
|
||
description: ''
|
||
code_samples: []
|
||
parameters:
|
||
- name: name
|
||
type: string
|
||
default:
|
||
summary: ''
|
||
- name: recursive
|
||
type: boolean
|
||
default: false
|
||
summary: ''
|
||
returns:
|
||
- type: Instance
|
||
summary: ''
|
||
tags:
|
||
- Deprecated
|
||
deprecation_message: |
|
||
This deprecated function is a variant of `Class.Instance:FindFirstChild()`
|
||
which should be used instead.
|
||
security: None
|
||
thread_safety: Unsafe
|
||
capabilities: []
|
||
- name: Instance:FindFirstChildOfClass
|
||
summary: |
|
||
Returns the first child of the `Class.Instance` whose
|
||
`Class.Object.ClassName|ClassName` is equal to the given class name.
|
||
description: |
|
||
Returns the first child of the `Class.Instance` whose
|
||
`Class.Object.ClassName|ClassName` is equal to the given `className`.
|
||
Unlike `Class.Instance:FindFirstChildWhichIsA()`, this method only returns
|
||
objects whose class matches `className`, ignoring class inheritance. If no
|
||
matching child is found, this method returns `nil`.
|
||
code_samples:
|
||
- Instance-FindFirstChildOfClass1
|
||
parameters:
|
||
- name: className
|
||
type: string
|
||
default:
|
||
summary: |
|
||
The `Class.Object.ClassName` to be looked for.
|
||
returns:
|
||
- type: Instance
|
||
summary: |
|
||
The `Class.Instance` found.
|
||
tags: []
|
||
deprecation_message: ''
|
||
security: None
|
||
thread_safety: Safe
|
||
capabilities: []
|
||
- name: Instance:FindFirstChildWhichIsA
|
||
summary: |
|
||
Returns the first child of the `Class.Instance` for whom
|
||
`Class.Object:IsA()` returns true for the given className.
|
||
description: |
|
||
Returns the first child of the `Class.Instance` for whom
|
||
`Class.Object:IsA()` returns true for the given className.
|
||
|
||
If no matching child is found, this method returns `nil`. If the optional
|
||
recursive argument is true, this method searches all descendants rather
|
||
than only the immediate children of the `Class.Instance`.
|
||
|
||
Unlike `Class.Instance:FindFirstChildOfClass()`, this method uses
|
||
`Class.Object:IsA()` which respects class inheritance. For example:
|
||
|
||
```lua
|
||
print(part:IsA("Part")) --> true
|
||
print(part:IsA("BasePart")) --> true
|
||
print(part:IsA("Instance")) --> true
|
||
```
|
||
|
||
Therefore, the following code sample will return the first
|
||
`Class.BasePart` child, regardless of if it is a `Class.WedgePart`,
|
||
`Class.MeshPart` or `Class.Part`.
|
||
|
||
```
|
||
local part = object:FindFirstChildWhichIsA("BasePart")
|
||
```
|
||
|
||
Developers looking for a child by name, should use
|
||
`Class.Instance:FindFirstChild()` instead.
|
||
code_samples: []
|
||
parameters:
|
||
- name: className
|
||
type: string
|
||
default:
|
||
summary: |
|
||
The `Class.Object.ClassName` to be searched for.
|
||
- name: recursive
|
||
type: boolean
|
||
default: false
|
||
summary: |
|
||
Whether or not the search should be conducted recursively.
|
||
returns:
|
||
- type: Instance
|
||
summary: |
|
||
The `Class.Instance` found.
|
||
tags: []
|
||
deprecation_message: ''
|
||
security: None
|
||
thread_safety: Safe
|
||
capabilities: []
|
||
- name: Instance:FindFirstDescendant
|
||
summary: |
|
||
Returns the first descendant found with the given `Class.Instance.Name`.
|
||
description: |
|
||
Returns the first descendant found with the given `Class.Instance.Name`.
|
||
|
||
This method is disabled and cannot be used. To find the first descendant
|
||
of an instance, consider using the `recursive` parameter on
|
||
`Class.Instance:FindFirstChild()` instead.
|
||
code_samples: []
|
||
parameters:
|
||
- name: name
|
||
type: string
|
||
default:
|
||
summary: |
|
||
The `Class.Instance.Name` to search for.
|
||
returns:
|
||
- type: Instance
|
||
summary: |
|
||
The `Class.Instance` found.
|
||
tags: []
|
||
deprecation_message: ''
|
||
security: None
|
||
thread_safety: Safe
|
||
capabilities: []
|
||
- name: Instance:GetActor
|
||
summary: |
|
||
Returns the `Class.Actor` associated with the Instance, if any.
|
||
description: |
|
||
If the `Class.Instance` is an `Class.Actor`, the `Class.Actor` itself is
|
||
returned. Otherwise, its closest ancestor `Class.Actor` is returned. If no
|
||
ancestor is an `Class.Actor`, the result is `nil`.
|
||
code_samples: []
|
||
parameters: []
|
||
returns:
|
||
- type: Actor?
|
||
summary: |
|
||
The `Class.Actor` found.
|
||
tags: []
|
||
deprecation_message: ''
|
||
security: None
|
||
thread_safety: Safe
|
||
capabilities: []
|
||
- name: Instance:GetAttribute
|
||
summary: |
|
||
Returns the value which has been assigned to the given attribute name.
|
||
description: |
|
||
This method returns the value which has been assigned to the given
|
||
attribute name. If no attribute has been assigned, `nil` is returned.
|
||
|
||
For example, the following code snippet sets and then gets the value of
|
||
the instance's `InitialPosition` attribute:
|
||
|
||
```lua
|
||
local Workspace = game:GetService("Workspace")
|
||
|
||
local part = Workspace.Part
|
||
part:SetAttribute("InitialPosition", part.Position)
|
||
|
||
local initialPosition = instance:GetAttribute("InitialPosition")
|
||
print(initialPosition)
|
||
```
|
||
|
||
##### See Also
|
||
|
||
- `Class.Instance:SetAttribute()` which sets the attribute with the given
|
||
name to the given value.
|
||
- `Class.Instance:GetAttributes()` which returns a dictionary of key‑value
|
||
pairs for each of the instance's attributes.
|
||
code_samples: []
|
||
parameters:
|
||
- name: attribute
|
||
type: string
|
||
default:
|
||
summary: |
|
||
The name of the attribute being retrieved.
|
||
returns:
|
||
- type: Variant
|
||
summary: |
|
||
The value which has been assigned to the given attribute name. If no
|
||
attribute has been assigned, `nil` is returned.
|
||
tags: []
|
||
deprecation_message: ''
|
||
security: None
|
||
thread_safety: Safe
|
||
capabilities: []
|
||
- name: Instance:GetAttributeChangedSignal
|
||
summary: |
|
||
Returns an event that fires when the given attribute changes.
|
||
description: |
|
||
This method returns an event that behaves exactly like the
|
||
`Class.Object.Changed|Changed` event, except that it only fires when the
|
||
specific given attribute changes; effectively it is similar to
|
||
`Class.Object:GetPropertyChangedSignal()|GetPropertyChangedSignal()` but
|
||
for attributes.
|
||
|
||
It's generally a good idea to use this method instead of a connection to
|
||
`Class.Object.Changed|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.
|
||
|
||
The following code example returns a signal that fires the function
|
||
`attributeChanged()` when the part's `InitialPosition` attribute changes:
|
||
|
||
```lua
|
||
local Workspace = game:GetService("Workspace")
|
||
|
||
local part = Workspace.Part
|
||
part:SetAttribute("InitialPosition", part.Position)
|
||
|
||
local function attributeChanged()
|
||
print("Attribute changed")
|
||
end
|
||
|
||
part:GetAttributeChangedSignal("InitialPosition"):Connect(attributeChanged)
|
||
```
|
||
|
||
See also `Class.Instance.AttributeChanged` which fires whenever any
|
||
attribute is changed on the instance.
|
||
code_samples: []
|
||
parameters:
|
||
- name: attribute
|
||
type: string
|
||
default:
|
||
summary: |
|
||
The name of the specified attribute for which the change signal is
|
||
being returned.
|
||
returns:
|
||
- type: RBXScriptSignal
|
||
summary: |
|
||
An event that fires when the given attribute changes.
|
||
tags: []
|
||
deprecation_message: ''
|
||
security: None
|
||
thread_safety: Unsafe
|
||
capabilities: []
|
||
- name: Instance:GetAttributes
|
||
summary: |
|
||
Returns a dictionary of the instance's attributes.
|
||
description: |
|
||
This method returns a dictionary of key‑value pairs for each attribute
|
||
where the key is the attribute's name and the value is a non‑`nil` value.
|
||
|
||
For example, the following code snippet outputs an instance's attributes
|
||
and values:
|
||
|
||
```lua
|
||
local Workspace = game:GetService("Workspace")
|
||
|
||
local part = Workspace.Part
|
||
part:SetAttribute("InitialPosition", part.Position)
|
||
part:SetAttribute("CanUse", true)
|
||
|
||
for name, value in part:GetAttributes() do
|
||
print(name .. " = " .. value)
|
||
end
|
||
```
|
||
|
||
See also `Class.Instance:GetAttribute()` which returns the value that has
|
||
been assigned to the given attribute name.
|
||
code_samples: []
|
||
parameters: []
|
||
returns:
|
||
- type: Dictionary
|
||
summary: |
|
||
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.
|
||
tags:
|
||
- CustomLuaState
|
||
deprecation_message: ''
|
||
security: None
|
||
thread_safety: Safe
|
||
capabilities: []
|
||
- name: Instance:GetChildren
|
||
summary: |
|
||
Returns an array containing all of the instance's children.
|
||
description: |
|
||
Returns an array (a numerically indexed table) containing all of the
|
||
instance's direct children, or every `Class.Instance` whose
|
||
`Class.Instance.Parent|Parent` is equal to the object. The array can be
|
||
iterated upon using either a numeric or generic `for` loop:
|
||
|
||
```lua
|
||
local Workspace = game:GetService("Workspace")
|
||
|
||
-- Numeric loop example
|
||
local children = Workspace:GetChildren()
|
||
for i = 1, #children do
|
||
local child = children[i]
|
||
print(child.Name .. " is child number " .. i)
|
||
end
|
||
```
|
||
|
||
```lua
|
||
local Workspace = game:GetService("Workspace")
|
||
|
||
-- Generic loop example
|
||
local children = Workspace:GetChildren()
|
||
for i, child in children do
|
||
print(child.Name .. " is child number " .. i)
|
||
end
|
||
```
|
||
|
||
Note that the returned array is **not** sorted in any particular order, so
|
||
manual sorting (for example using `Library.table.sort()`) is advised for
|
||
sorting the children returned by this method.
|
||
|
||
See also the `Class.Instance:GetDescendants()|GetDescendants()` method.
|
||
code_samples:
|
||
- Instance-GetChildren1
|
||
parameters: []
|
||
returns:
|
||
- type: Instances
|
||
summary: |
|
||
An array containing the instance's children.
|
||
tags: []
|
||
deprecation_message: ''
|
||
security: None
|
||
thread_safety: Safe
|
||
capabilities: []
|
||
- name: Instance:getChildren
|
||
summary: ''
|
||
description: ''
|
||
code_samples: []
|
||
parameters: []
|
||
returns:
|
||
- type: Instances
|
||
summary: ''
|
||
tags:
|
||
- Deprecated
|
||
deprecation_message: |
|
||
This deprecated function is a variant of `Class.Instance:GetChildren()`
|
||
which should be used instead.
|
||
security: None
|
||
thread_safety: Unsafe
|
||
capabilities: []
|
||
- name: Instance:GetDebugId
|
||
summary: |
|
||
Returns a coded string of the debug ID used internally by Roblox.
|
||
description: |
|
||
Returns a coded string of the debug ID used internally by Roblox. Note
|
||
that:
|
||
|
||
- This item is protected. Attempting to use it in a `Class.Script` or
|
||
`Class.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).
|
||
code_samples:
|
||
- Instance-GetDebugId1
|
||
parameters:
|
||
- name: scopeLength
|
||
type: int
|
||
default: 4
|
||
summary: |
|
||
The scope length.
|
||
returns:
|
||
- type: string
|
||
summary: |
|
||
The Debug ID string.
|
||
tags:
|
||
- NotBrowsable
|
||
deprecation_message: ''
|
||
security: PluginSecurity
|
||
thread_safety: Unsafe
|
||
capabilities: []
|
||
- name: Instance:GetDescendants
|
||
summary: |
|
||
Returns an array containing all of the descendants of the instance.
|
||
description: |
|
||
This object method returns an array that contains all of the descendants
|
||
of that object. Unlike `Class.Instance:GetChildren()`, which only returns
|
||
the immediate children of an object, this method finds every child of the
|
||
object, every child of those children, and so on.
|
||
|
||
Note that the returned array is **not** sorted in any particular order, so
|
||
manual sorting (for example using `Library.table.sort()`) is advised for
|
||
sorting the descendants returned by this method. Also consdier the
|
||
`Class.Instance:QueryDescendants()|QueryDescendants()` method to query
|
||
descendants by a combination of selectors and combinators.
|
||
code_samples:
|
||
- Instance-GetDescendants1
|
||
parameters: []
|
||
returns:
|
||
- type: Array
|
||
summary: |
|
||
An array containing the instance's descendants.
|
||
tags:
|
||
- CustomLuaState
|
||
deprecation_message: ''
|
||
security: None
|
||
thread_safety: Safe
|
||
capabilities: []
|
||
- name: Instance:GetFullName
|
||
summary: |
|
||
Returns a string describing the instance's ancestry.
|
||
description: |
|
||
Returns a string describing the instance's ancestry. The string is a
|
||
concatenation of the `Class.Instance.Name|Name` of the object and its
|
||
ancestors, separated by periods. The `Class.DataModel` (`game`) is not
|
||
considered. For example, a `Class.Part` in the `Class.Workspace` may
|
||
return `Class.Workspace.Part`.
|
||
|
||
When called on an `Class.Instance` that is not a descendant of the
|
||
`Class.DataModel`, this method considers all ancestors up to and including
|
||
the topmost one without a `Class.Instance.Parent|Parent`.
|
||
|
||
This method is useful for logging and debugging. You shouldn't attempt to
|
||
parse the returned string for any useful operation; this method does not
|
||
escape periods (or any other symbol) in object names. In other words,
|
||
although its output often appears to be a valid Luau identifier, it is not
|
||
guaranteed.
|
||
code_samples:
|
||
- Instance-GetFullName1
|
||
- instance-getfullname-lua-implementation
|
||
parameters: []
|
||
returns:
|
||
- type: string
|
||
summary: |
|
||
The full name of the `Class.Instance`.
|
||
tags: []
|
||
deprecation_message: ''
|
||
security: None
|
||
thread_safety: Safe
|
||
capabilities: []
|
||
- name: Instance:GetStyled
|
||
summary: |
|
||
Returns the styled or explicitly modified value of the specified property,
|
||
or else the default property value if it hasn't been styled/modified.
|
||
description: |
|
||
This method returns the styled or explicitly modified value of the
|
||
specified property, or else the default property value if it hasn't been
|
||
styled/modified. This differs slightly from accessing the property value
|
||
directly, such as `[GuiObject].Rotation`, which returns the default or
|
||
modified value of the property.
|
||
|
||
```lua
|
||
local Players = game:GetService("Players")
|
||
local ReplicatedStorage = game:GetService("ReplicatedStorage")
|
||
|
||
local player = Players.LocalPlayer
|
||
local playerGui = player.PlayerGui
|
||
local HUDContainer = playerGui:WaitForChild("HUDContainer")
|
||
|
||
local coreSheet = ReplicatedStorage:FindFirstChild("CoreSheet")
|
||
local rule = coreSheet:FindFirstChildWhichIsA("StyleRule")
|
||
rule.Selector = "TextButton"
|
||
|
||
-- Reference to a button
|
||
local button = HUDContainer:FindFirstChildWhichIsA("TextButton")
|
||
|
||
print(button:GetStyled("Rotation")) --> 0 (default value)
|
||
print(button.Rotation) --> 0 (default value)
|
||
|
||
-- Apply rotation through style rule property
|
||
rule:SetProperty("Rotation", 30)
|
||
|
||
print(button:GetStyled("Rotation")) --> 30 (styled value based on rule)
|
||
print(button.Rotation) --> 0 (default value)
|
||
|
||
-- Explicitly modify/override styled property
|
||
button.Rotation = 45
|
||
|
||
print(button:GetStyled("Rotation")) --> 45 (modified value)
|
||
print(button.Rotation) --> 45 (modified value)
|
||
```
|
||
code_samples: []
|
||
parameters:
|
||
- name: name
|
||
type: string
|
||
default:
|
||
summary: |
|
||
Name of the property to query.
|
||
- name: selector
|
||
type: string?
|
||
default:
|
||
summary: |
|
||
Optional selector for the pseudo instance you are targeting on the
|
||
instance.
|
||
returns:
|
||
- type: Variant
|
||
summary: |
|
||
The styled or explicitly modified value of the specified property, or
|
||
else the default property value if it hasn't been styled/modified.
|
||
tags: []
|
||
deprecation_message: ''
|
||
security: None
|
||
thread_safety: Unsafe
|
||
capabilities: []
|
||
- name: Instance:GetStyledPropertyChangedSignal
|
||
summary: ''
|
||
description: |
|
||
This method returns an event that behaves exactly like the
|
||
`Class.Instance.StyledPropertiesChanged|StyledPropertiesChanged` event,
|
||
except that it only fires when the given style property changes. It's
|
||
generally a good idea to use this method instead of a connection to
|
||
`Class.Instance.StyledPropertiesChanged|StyledPropertiesChanged` 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.
|
||
|
||
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.
|
||
|
||
```lua
|
||
local Players = game:GetService("Players")
|
||
|
||
local player = Players.LocalPlayer
|
||
local playerGui = player.PlayerGui
|
||
local HUDContainer = playerGui:WaitForChild("HUDContainer")
|
||
local meterBar = HUDContainer.MeterBar
|
||
|
||
local function stylePropertyChanged()
|
||
print("Style property changed!")
|
||
end
|
||
|
||
meterBar:GetStyledPropertyChangedSignal("AnchorPoint"):Connect(stylePropertyChanged)
|
||
```
|
||
code_samples: []
|
||
parameters:
|
||
- name: property
|
||
type: string
|
||
default:
|
||
summary: |
|
||
Name of the style property for which to listen for changes.
|
||
returns:
|
||
- type: RBXScriptSignal
|
||
summary: |
|
||
Event that fires when the given style property changes.
|
||
tags: []
|
||
deprecation_message: ''
|
||
security: None
|
||
thread_safety: Unsafe
|
||
capabilities: []
|
||
- name: Instance:GetTags
|
||
summary: |
|
||
Gets an array of all tags applied to the instance.
|
||
description: |
|
||
This method returns an array of the tags applied to the given instance, as
|
||
strings. You can add tags either in Studio in the
|
||
[Properties](../../../studio/properties.md) window or at runtime with
|
||
`Class.Instance:AddTag()|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
|
||
`Class.Instance:HasTag()|HasTag()` to check for a specific tag.
|
||
code_samples: []
|
||
parameters: []
|
||
returns:
|
||
- type: Array
|
||
summary: ''
|
||
tags: []
|
||
deprecation_message: ''
|
||
security: None
|
||
thread_safety: Safe
|
||
capabilities: []
|
||
- name: Instance:HasTag
|
||
summary: |
|
||
Check whether the instance has a given tag.
|
||
description: |
|
||
This method returns `true` if the provided tag has been added to the
|
||
object. You can add tags either in Studio in the
|
||
[Properties](../../../studio/properties.md) window or at runtime with
|
||
`Class.Instance:AddTag()|AddTag()`.
|
||
code_samples: []
|
||
parameters:
|
||
- name: tag
|
||
type: string
|
||
default:
|
||
summary: ''
|
||
returns:
|
||
- type: boolean
|
||
summary: ''
|
||
tags: []
|
||
deprecation_message: ''
|
||
security: None
|
||
thread_safety: Safe
|
||
capabilities: []
|
||
- name: Instance:IsAncestorOf
|
||
summary: |
|
||
Returns true if an `Class.Instance` is an ancestor of the given
|
||
descendant.
|
||
description: |
|
||
Returns true if an `Class.Instance` is an ancestor of the given
|
||
descendant.
|
||
|
||
An `Class.Instance` is considered the ancestor of an object if the
|
||
object's `Class.Instance.Parent` or one of it's parent's
|
||
`Class.Instance.Parent` is set to the `Class.Instance`.
|
||
|
||
See also, `Class.Instance:IsDescendantOf()`.
|
||
code_samples:
|
||
- Instance-IsAncestorOf1
|
||
parameters:
|
||
- name: descendant
|
||
type: Instance
|
||
default:
|
||
summary: |
|
||
The descendant `Class.Instance`.
|
||
returns:
|
||
- type: boolean
|
||
summary: |
|
||
True if the `Class.Instance` is an ancestor of the given descendant.
|
||
tags: []
|
||
deprecation_message: ''
|
||
security: None
|
||
thread_safety: Safe
|
||
capabilities: []
|
||
- name: Instance:IsDescendantOf
|
||
summary: |
|
||
Returns `true` if an `Class.Instance` is a descendant of the given
|
||
ancestor.
|
||
description: |
|
||
Returns `true` if an `Class.Instance` is a descendant of the given
|
||
ancestor.
|
||
|
||
Note that `IsDescendantOf()` cannot be used with a parameter of `nil` to
|
||
check if an object has been removed.
|
||
|
||
See also `Class.Instance:IsAncestorOf()`.
|
||
code_samples:
|
||
- Instance-IsDescendantOf1
|
||
parameters:
|
||
- name: ancestor
|
||
type: Instance
|
||
default:
|
||
summary: |
|
||
The ancestor `Class.Instance`.
|
||
returns:
|
||
- type: boolean
|
||
summary: |
|
||
True if the `Class.Instance` is a descendant of the given ancestor.
|
||
tags: []
|
||
deprecation_message: ''
|
||
security: None
|
||
thread_safety: Safe
|
||
capabilities: []
|
||
- name: Instance:isDescendantOf
|
||
summary: ''
|
||
description: ''
|
||
code_samples: []
|
||
parameters:
|
||
- name: ancestor
|
||
type: Instance
|
||
default:
|
||
summary: ''
|
||
returns:
|
||
- type: boolean
|
||
summary: ''
|
||
tags:
|
||
- Deprecated
|
||
deprecation_message: |
|
||
This deprecated function is a variant of `Class.Instance:IsDescendantOf()`
|
||
which should be used instead.
|
||
security: None
|
||
thread_safety: Unsafe
|
||
capabilities: []
|
||
- name: Instance:IsPropertyModified
|
||
summary: |
|
||
Returns `true` if the value stored in the specified property is not equal
|
||
to the code-instantiated default.
|
||
description: |
|
||
This method indicates whether a specific property has been modified from
|
||
the code‑instantiated default. If called on an instance newly created via
|
||
code (`Datatype.Instance.new()`), this method will return `false`. If
|
||
called on an object newly created by Studio workflows such as
|
||
[Explorer](../../../studio/explorer.md) window insertion, the result may
|
||
differ.
|
||
|
||
For example, querying the
|
||
`Class.TextLabel.BackgroundColor3|BackgroundColor3` property of a
|
||
`Class.TextLabel` inserted via the [Explorer](../../../studio/explorer.md)
|
||
will return `true`, but querying the same property of a `Class.TextLabel`
|
||
created through `Datatype.Instance.new()` will return `false`, assuming no
|
||
other changes were made to its
|
||
`Class.TextLabel.BackgroundColor3|BackgroundColor3`.
|
||
|
||
Note that if this method returns `true`, styling will **not** affect the
|
||
property because explicitly modifying a property takes precedence over
|
||
styling it. To reset a property to its code‑instantiated default and allow
|
||
styling on it, use
|
||
`Class.Instance:ResetPropertyToDefault()|ResetPropertyToDefault()`.
|
||
code_samples: []
|
||
parameters:
|
||
- name: property
|
||
type: string
|
||
default:
|
||
summary: |
|
||
Name of the property to query.
|
||
returns:
|
||
- type: boolean
|
||
summary: |
|
||
Boolean indicating whether the property is modified from its
|
||
code‑instantiated default.
|
||
tags: []
|
||
deprecation_message: ''
|
||
security: None
|
||
thread_safety: Unsafe
|
||
capabilities: []
|
||
- name: Instance:QueryDescendants
|
||
summary: ''
|
||
description: |
|
||
This object method returns an array which contains the descendants of that
|
||
object matching the provided `selector` string. The `selector` string can
|
||
include multiple selectors and combinators to match characteristics such
|
||
as the class name, instance name, hierarchy relationships, as well as
|
||
specific values of instance properties and attributes. The `selector`
|
||
grammar is similar to the one used in `Class.StyleRule` with only a few
|
||
differences regarding which parts of the grammar are supported or not.
|
||
|
||
#### Selectors
|
||
|
||
- `ClassName` — Matches instances of the specified class in a
|
||
`Class.Object:IsA()` relationship.
|
||
- `.Tag` — Matches instances tagged with a `Class.CollectionService` tag.
|
||
- `#Name` — Matches instances of a specific `Class.Instance.Name`.
|
||
- `[property = value]` — Matches instances which have the specified
|
||
property and that property has the specified value. Boolean, number, and
|
||
string values are supported. Letters, numbers, `_`, and `-` can be used
|
||
without putting the value in quotation marks.
|
||
- `[$attribute]` — Matches instances which have the specified
|
||
[attribute](../../../studio/properties.md#instance-attributes) set.
|
||
- `[$attribute = value]` — Matches instances which have the specified
|
||
attribute **and** that attribute has the specified value. Same
|
||
limitations apply as for property selectors.
|
||
|
||
Selectors can also be combined. For example,
|
||
`Model.Apple[$Variety = Fuji][$Flavor = 4]` will match instances which are
|
||
a `Class.Model` tagged as `Apple` and which have a `Variety` attribute
|
||
equal to `Fuji` as well as a `Flavor` attribute equal to `4`.
|
||
|
||
```lua
|
||
local Workspace = game:GetService("Workspace")
|
||
|
||
-- Get all MeshPart descendants
|
||
print(Workspace:QueryDescendants("MeshPart"))
|
||
|
||
-- Get all descendants tagged as "Fruit"
|
||
print(Workspace:QueryDescendants(".Fruit"))
|
||
|
||
-- Get all descendants with the name "RedTree"
|
||
print(Workspace:QueryDescendants("#RedTree"))
|
||
|
||
-- Get all descendants with CanCollide property set to false
|
||
print(Workspace:QueryDescendants("[CanCollide = false]"))
|
||
|
||
-- Get all descendants with a "FuelCapacity" attribute assigned
|
||
print(Workspace:QueryDescendants("[$FuelCapacity]"))
|
||
-- Get all descendants with a "FuelCapacity" attribute set to 75
|
||
print(Workspace:QueryDescendants("[$FuelCapacity = 75]"))
|
||
```
|
||
|
||
#### Combinators
|
||
|
||
Combinators let you mix basic selectors to match deeper hierarchy
|
||
relationships.
|
||
|
||
- `>` — Matches instances that are **direct children** of the previous
|
||
filter matches.
|
||
|
||
- `>>` — Matches instances that are **descendants** of the previous filter
|
||
matches. This is the default first filter, meaning that `SpotLight.Red`
|
||
is the same as `>> SpotLight.Red`.
|
||
|
||
- `,` — Specifies a list of multiple independent selectors for the
|
||
descendant query. Only elements matching the filter are placed in the
|
||
returned array; `nil` will not be included for non‑matches in a query
|
||
list.
|
||
|
||
```lua
|
||
local Workspace = game:GetService("Workspace")
|
||
|
||
-- Get direct children of any Model that are tagged as "SwordPart"
|
||
print(Workspace:QueryDescendants("Model > .SwordPart"))
|
||
|
||
-- Get direct children which are a Part and are tagged as "Apple"
|
||
print(Workspace:QueryDescendants("> Part.Apple"))
|
||
|
||
-- Get descendants of any Model with an attribute "OnFire" set to true
|
||
print(Workspace:QueryDescendants("Model >> [$OnFire = true]"))
|
||
|
||
-- Get MeshPart descendants tagged as "SwordPart" OR with an attribute "OnFire" set to true
|
||
print(Workspace:QueryDescendants("MeshPart.SwordPart, MeshPart[$OnFire = true]"))
|
||
```
|
||
|
||
#### Pseudo-class selectors
|
||
|
||
- `:not(complex-selector-list)` — Allows selecting instances which do
|
||
**not** match any of the selectors inside, effectively performing a
|
||
negation of the selectors. Since the expression inside is a list of
|
||
complex selectors, it's possible to filter based on multiple conditions.
|
||
|
||
- `:has(relative-selector-list)` — Allows selecting instances based on
|
||
which instances they contain inside. The selector list is evaluated
|
||
relative to each instance.
|
||
|
||
```lua
|
||
local Workspace = game:GetService("Workspace")
|
||
|
||
-- Get all descendants which are NOT of class SpotLight
|
||
print(Workspace:QueryDescendants(":not(SpotLight)"))
|
||
-- Get all descendants which are NOT of class SpotLight OR PointLight
|
||
print(Workspace:QueryDescendants(":not(SpotLight, PointLight)"))
|
||
-- Get all descendants which do NOT have an attribute "OnFire"
|
||
print(Workspace:QueryDescendants(":not([$OnFire])"))
|
||
-- Get all descendants EXCEPT children of a Model tagged as "SwordPart"
|
||
print(Workspace:QueryDescendants(":not(Model > .SwordPart)"))
|
||
|
||
-- Get descendants which contain a Tool instance as their own descendant
|
||
print(Workspace:QueryDescendants(":has(Tool)"))
|
||
-- Get MeshPart descendants which contain a direct child tagged as "SwordPart"
|
||
print(Workspace:QueryDescendants("MeshPart:has(> .SwordPart)"))
|
||
|
||
-- Get MeshPart descendants with direct children NOT of SurfaceAppearance or Texture class
|
||
print(Workspace:QueryDescendants("MeshPart:has(> :not(SurfaceAppearance, Texture))"))
|
||
```
|
||
code_samples: []
|
||
parameters:
|
||
- name: selector
|
||
type: string
|
||
default:
|
||
summary: |
|
||
Selector string used to filter elements.
|
||
returns:
|
||
- type: Instances
|
||
summary: |
|
||
An array of instances (empty if nothing matched the selector).
|
||
tags:
|
||
- CustomLuaState
|
||
deprecation_message: ''
|
||
security: None
|
||
thread_safety: Unsafe
|
||
capabilities: []
|
||
- name: Instance:Remove
|
||
summary: |
|
||
Sets the object's `Parent` to `nil`, and does the same for all its
|
||
descendants.
|
||
description: |
|
||
This method sets the object's `Class.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.
|
||
code_samples:
|
||
- Instance-Remove1
|
||
parameters: []
|
||
returns:
|
||
- type: ()
|
||
summary: ''
|
||
tags:
|
||
- Deprecated
|
||
deprecation_message: |
|
||
This item is deprecated in favor of `Class.Instance:Destroy()` and
|
||
`Class.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.
|
||
security: None
|
||
thread_safety: Unsafe
|
||
capabilities: []
|
||
- name: Instance:remove
|
||
summary: ''
|
||
description: ''
|
||
code_samples: []
|
||
parameters: []
|
||
returns:
|
||
- type: ()
|
||
summary: ''
|
||
tags:
|
||
- Deprecated
|
||
deprecation_message: |
|
||
This deprecated function is a variant of `Class.Instance:Remove()` which
|
||
has also been deprecated. Neither function should be used in new work.
|
||
security: None
|
||
thread_safety: Unsafe
|
||
capabilities: []
|
||
- name: Instance:RemoveTag
|
||
summary: |
|
||
Removes a tag from the instance.
|
||
description: |
|
||
This 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 `Class.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.
|
||
code_samples: []
|
||
parameters:
|
||
- name: tag
|
||
type: string
|
||
default:
|
||
summary: ''
|
||
returns:
|
||
- type: ()
|
||
summary: ''
|
||
tags: []
|
||
deprecation_message: ''
|
||
security: None
|
||
thread_safety: Unsafe
|
||
capabilities: []
|
||
- name: Instance:ResetPropertyToDefault
|
||
summary: |
|
||
Resets a property to its default value.
|
||
description: |
|
||
Resets a property to its default value. For example, calling
|
||
`ResetPropertyToDefault("Rotation")` on a `Class.TextLabel` is equivalent
|
||
to setting its `Class.TextLabel.Rotation|Rotation` to `0` (the property's
|
||
default value). This method can be used to ensure styling will override
|
||
this property's default value.
|
||
code_samples: []
|
||
parameters:
|
||
- name: property
|
||
type: string
|
||
default:
|
||
summary: |
|
||
Name of the property to reset.
|
||
returns:
|
||
- type: ()
|
||
summary: ''
|
||
tags: []
|
||
deprecation_message: ''
|
||
security: None
|
||
thread_safety: Unsafe
|
||
capabilities: []
|
||
- name: Instance:SetAttribute
|
||
summary: |
|
||
Sets the attribute with the given name to the given value.
|
||
description: |
|
||
This method sets the attribute with the given name to the given value. If
|
||
the value given is `nil`, the attribute will be removed, since `nil` is
|
||
returned by default.
|
||
|
||
For example, the following code snippet sets the instance's
|
||
`InitialPosition` attribute to `Datatype.Vector3|Vector3.new(0, 10, 0)`:
|
||
|
||
```lua
|
||
local Workspace = game:GetService("Workspace")
|
||
|
||
local part = Workspace.Part
|
||
part:SetAttribute("InitialPosition", Vector3.new(0, 10, 0))
|
||
```
|
||
|
||
##### Limitations
|
||
|
||
Naming requirements and restrictions:
|
||
|
||
- Names must only use alphanumeric characters.
|
||
- You may also include periods, hyphens, slashes, and underscores.
|
||
- No spaces or unique symbols (such as @, ~, !) 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
|
||
|
||
- `Class.Instance:GetAttribute()` which returns the value that has been
|
||
assigned to the given attribute name.
|
||
- `Class.Instance:GetAttributes()` which returns a dictionary of key‑value
|
||
pairs for each of the instance's attributes.
|
||
code_samples: []
|
||
parameters:
|
||
- name: attribute
|
||
type: string
|
||
default:
|
||
summary: |
|
||
The name of the attribute being set.
|
||
- name: value
|
||
type: Variant
|
||
default:
|
||
summary: |
|
||
The value to set the specified attribute to.
|
||
returns:
|
||
- type: ()
|
||
summary: ''
|
||
tags: []
|
||
deprecation_message: ''
|
||
security: None
|
||
thread_safety: Unsafe
|
||
capabilities: []
|
||
- name: Instance:WaitForChild
|
||
summary: |
|
||
Returns the child of the `Class.Instance` with the given name. If the
|
||
child does not exist, it will yield the current thread until it does.
|
||
description: |
|
||
Returns the child of the `Class.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
|
||
|
||
`Class.Instance:WaitForChild()|WaitForChild()` is extremely important when
|
||
working on code run by the client in a `Class.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 `Class.Workspace.StreamingEnabled` set to true,
|
||
`Class.BasePart|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 method does not yield if a child with the given name exists when
|
||
the call is made.
|
||
- `Class.Instance:FindFirstChild()` is a more efficient alternative to
|
||
`Class.Instance:WaitForChild()|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.
|
||
code_samples:
|
||
- Instance-WaitForChild1
|
||
parameters:
|
||
- name: childName
|
||
type: string
|
||
default:
|
||
summary: |
|
||
The `Class.Instance.Name` to be looked for.
|
||
- name: timeOut
|
||
type: double
|
||
default:
|
||
summary: |
|
||
An optional time out parameter.
|
||
returns:
|
||
- type: Instance
|
||
summary: |
|
||
The `Class.Instance` found.
|
||
tags:
|
||
- CustomLuaState
|
||
- CanYield
|
||
deprecation_message: ''
|
||
security: None
|
||
thread_safety: Unsafe
|
||
capabilities: []
|
||
events:
|
||
- name: Instance.AncestryChanged
|
||
summary: |
|
||
Fires when the `Class.Instance.Parent` property of the object or one of
|
||
its ancestors is changed.
|
||
description: |
|
||
Fires when the `Class.Instance.Parent` property of the object or one of
|
||
its ancestors is changed.
|
||
|
||
This event includes two parameters: `child` refers to the `Class.Instance`
|
||
whose `Class.Instance.Parent` was actually changed, while `parent` refers
|
||
to this instance's new `Class.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 `Class.Instance:Destroy()`,
|
||
use the `Class.Instance.Destroying` event instead.
|
||
code_samples:
|
||
- Instance-AncestryChanged1
|
||
parameters:
|
||
- name: child
|
||
type: Instance
|
||
default:
|
||
summary: |
|
||
The `Class.Instance` whose `Class.Instance.Parent` has been changed.
|
||
- name: parent
|
||
type: Instance
|
||
default:
|
||
summary: |
|
||
The new `Class.Instance.Parent` of the `Class.Instance` whose
|
||
`Class.Instance.Parent` was changed.
|
||
tags: []
|
||
deprecation_message: ''
|
||
security: None
|
||
capabilities: []
|
||
- name: Instance.AttributeChanged
|
||
summary: |
|
||
Fires whenever an attribute is changed on the `Class.Instance`.
|
||
description: |
|
||
This event fires whenever any attribute is changed on the instance,
|
||
including when an attribute is set to `nil`. The name of the changed
|
||
attribute is passed to the connected function.
|
||
|
||
For example, the following code snippet connects the `attributeChanged()`
|
||
function to fire whenever one of the part's attributes changes:
|
||
|
||
```lua
|
||
local Workspace = game:GetService("Workspace")
|
||
|
||
local part = Workspace.Part
|
||
|
||
local function attributeChanged(attributeName)
|
||
print(attributeName, "changed")
|
||
end
|
||
|
||
part.AttributeChanged:Connect(attributeChanged)
|
||
```
|
||
|
||
See also `Class.Instance:GetAttributeChangedSignal()` which returns an
|
||
event that fires when a specific given attribute changes.
|
||
code_samples: []
|
||
parameters:
|
||
- name: attribute
|
||
type: string
|
||
default:
|
||
summary: |
|
||
The name of the attribute that has been changed.
|
||
tags: []
|
||
deprecation_message: ''
|
||
security: None
|
||
capabilities: []
|
||
- name: Instance.ChildAdded
|
||
summary: |
|
||
Fires after an object is parented to this `Class.Instance`.
|
||
description: |
|
||
Fires after an object is parented to this `Class.Instance`.
|
||
|
||
Note, when using this method on a client to detect objects created by the
|
||
server it is necessary to use `Class.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:
|
||
|
||
```
|
||
local Workspace = game:GetService("Workspace")
|
||
|
||
Workspace.ChildAdded:Connect(function(child)
|
||
-- Use WaitForChild() since descendants may not have replicated yet
|
||
local head = child:WaitForChild("Head")
|
||
end)
|
||
```
|
||
|
||
Note, this event only operates for immediate children of the
|
||
`Class.Instance`. For an event that captures all descendants, use
|
||
`Class.Instance.DescendantAdded`.
|
||
|
||
See also `Class.Instance.ChildRemoved`.
|
||
code_samples:
|
||
- Instance-ChildAdded1
|
||
parameters:
|
||
- name: child
|
||
type: Instance
|
||
default:
|
||
summary: |
|
||
The `Class.Instance` that has been added.
|
||
tags: []
|
||
deprecation_message: ''
|
||
security: None
|
||
capabilities: []
|
||
- name: Instance.childAdded
|
||
summary: ''
|
||
description: ''
|
||
code_samples: []
|
||
parameters:
|
||
- name: child
|
||
type: Instance
|
||
default:
|
||
summary: ''
|
||
tags:
|
||
- Deprecated
|
||
deprecation_message: |
|
||
This deprecated event is a variant of `Class.Instance.ChildAdded` which
|
||
should be used instead.
|
||
security: None
|
||
capabilities: []
|
||
- name: Instance.ChildRemoved
|
||
summary: |
|
||
Fires after a child is removed from this `Class.Instance`.
|
||
description: |
|
||
Fires after a child is removed from this `Class.Instance`.
|
||
|
||
Removed refers to when an object's parent is changed from this
|
||
`Class.Instance` to something other than this `Class.Instance`. Note, this
|
||
event will also fire when a child is destroyed (using
|
||
`Class.Instance:Destroy()`) as the destroy function sets an object's
|
||
parent to `nil`.
|
||
|
||
This event only operates for immediate children of the `Class.Instance`.
|
||
For an event that captures all descendants, use
|
||
`Class.Instance.DescendantRemoving`.
|
||
|
||
See also `Class.Instance.ChildAdded`.
|
||
code_samples:
|
||
- Instance-ChildRemoved1
|
||
parameters:
|
||
- name: child
|
||
type: Instance
|
||
default:
|
||
summary: |
|
||
The `Class.Instance` that has been removed.
|
||
tags: []
|
||
deprecation_message: ''
|
||
security: None
|
||
capabilities: []
|
||
- name: Instance.DescendantAdded
|
||
summary: |
|
||
Fires after a descendant is added to the `Class.Instance`.
|
||
description: |
|
||
This event fires after a descendant is added to the `Class.Instance`.
|
||
|
||
As it fires for every descendant, parenting an object to the
|
||
`Class.Instance` will fire the event for this object and all of its
|
||
descendants individually.
|
||
|
||
If you're only concerned with the **direct children** of the
|
||
`Class.Instance`, use `Class.Instance.ChildAdded` instead.
|
||
|
||
See also `Class.Instance.DescendantRemoving`.
|
||
code_samples:
|
||
- Instance-DescendantAdded1
|
||
parameters:
|
||
- name: descendant
|
||
type: Instance
|
||
default:
|
||
summary: |
|
||
The `Class.Instance` that has been added.
|
||
tags: []
|
||
deprecation_message: ''
|
||
security: None
|
||
capabilities: []
|
||
- name: Instance.DescendantRemoving
|
||
summary: |
|
||
Fires immediately before a descendant of the `Class.Instance` is removed.
|
||
description: |
|
||
This event fires **immediately before** the parent `Class.Instance`
|
||
changes such that a **descendant** instance will no longer be a
|
||
descendant. `Class.Instance:Destroy()|Destroy()` changes an instance's
|
||
`Class.Instance.Parent|Parent` to `nil`, so calling that method on a
|
||
descendant of the parent will cause this event to fire.
|
||
|
||
Since this event fires **before** the descendant's removal, the parent of
|
||
the descendant will be unchanged at the time of this event firing. If the
|
||
descendant is also a **direct child** of the parent, this event will fire
|
||
before `Class.Instance.ChildRemoved`.
|
||
|
||
If a descendant has children, this event fires with the descendant first,
|
||
followed by its descendants.
|
||
|
||
##### Warning
|
||
|
||
This event fires with the descendant object that is being removed.
|
||
Attempting to set the `Class.Instance.Parent|Parent` of the descendant to
|
||
something else will fail. Below is an example that demonstrates this:
|
||
|
||
```
|
||
local Workspace = game:GetService("Workspace")
|
||
|
||
Workspace.DescendantRemoving:Connect(function(descendant)
|
||
-- Do not manipulate the parent of the descendant in this function!
|
||
-- This event fires BECAUSE the parent was manipulated, and the change hasn't happened yet
|
||
-- 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
|
||
```
|
||
|
||
See also `Class.Instance.DescendantAdded|DescendantAdded`.
|
||
code_samples:
|
||
- Instance-DescendantRemoving1
|
||
parameters:
|
||
- name: descendant
|
||
type: Instance
|
||
default:
|
||
summary: |
|
||
The `Class.Instance` that is being removed.
|
||
tags: []
|
||
deprecation_message: ''
|
||
security: None
|
||
capabilities: []
|
||
- name: Instance.Destroying
|
||
summary: |
|
||
Fires immediately before (or is deferred until after) the instance is
|
||
destroyed via `Class.Instance:Destroy()`.
|
||
description: |
|
||
The `Class.Instance` will never be deleted from memory while a connected
|
||
function is still using it. However, if the function yields at any point,
|
||
the `Class.Instance` and its descendants will be parented to `nil`.
|
||
|
||
If the `Class.Workspace.SignalBehavior` property is set to
|
||
`Enum.SignalBehavior.Immediate`, this event fires immediately before the
|
||
`Class.Instance` or one of its ancestors is destroyed with
|
||
`Class.Instance:Destroy()`.
|
||
|
||
If the `Class.Workspace.SignalBehavior` property is set to
|
||
`Enum.SignalBehavior.Deferred`, this event fires at the next resumption
|
||
point, which will be after the `Class.Instance` or one of its ancestors is
|
||
destroyed with `Class.Instance:Destroy()`.
|
||
|
||
With `Enum.SignalBehavior.Deferred|Deferred` behavior, connecting a script
|
||
to its own `Class.Instance.Destroying` event is problematic, as the script
|
||
will be destroyed before the callback can be called (meaning it will not
|
||
execute).
|
||
|
||
When deleting an `Class.Instance` in Studio, such as manually deleting
|
||
through the [Explorer](../../../studio/explorer.md) or through a plugin,
|
||
the `Class.Instance` isn't destroyed. Instead, the parent is set to `nil`
|
||
which you can track with `Class.Instance.AncestryChanged`.
|
||
code_samples:
|
||
- Instance-Destroying-Immediate
|
||
- Instance-Destroying-Deferred
|
||
parameters: []
|
||
tags: []
|
||
deprecation_message: ''
|
||
security: None
|
||
capabilities: []
|
||
- name: Instance.StyledPropertiesChanged
|
||
summary: |
|
||
Fires whenever any style property is changed on the instance, including
|
||
when a property is set to `nil`.
|
||
description: |
|
||
This event fires whenever any style property is changed on the instance,
|
||
including when a property is set to `nil`.
|
||
|
||
```lua
|
||
local Players = game:GetService("Players")
|
||
|
||
local player = Players.LocalPlayer
|
||
local playerGui = player.PlayerGui
|
||
local HUDContainer = playerGui:WaitForChild("HUDContainer")
|
||
local meterBar = HUDContainer.MeterBar
|
||
|
||
local function stylePropertyChanged()
|
||
print("Styled properties changed")
|
||
end
|
||
|
||
meterBar:StyledPropertiesChanged():Connect(stylePropertyChanged)
|
||
```
|
||
code_samples: []
|
||
parameters: []
|
||
tags: []
|
||
deprecation_message: ''
|
||
security: None
|
||
capabilities: []
|
||
callbacks: []
|