-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
Instance.yaml
1896 lines (1740 loc) · 64.5 KB
/
Instance.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
name: Instance
type: class
category:
memory_category: Instances
summary: |
Instance is the base class for all classes in the Roblox class hierarchy.
description: |
Instance 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 Instance. It is not possible to directly create Instance objects.
Instance has a special function called `Datatype.Instance.new()` which is used
to create objects via code. This function takes the name of the class as a
parameter and returns the created object. Abstract classes and services cannot
be created with the Instance.new function.
code_samples:
inherits: []
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: bool
tags: []
deprecation_message: ''
security:
read: None
write: None
thread_safety: ReadSafe
category: Behavior
serialization:
can_load: false
can_save: false
- name: Instance.Capabilities
summary: ''
description: ''
code_samples: []
type: SecurityCapabilities
tags: []
deprecation_message: ''
security:
read: RobloxScriptSecurity
write: RobloxScriptSecurity
thread_safety: ReadSafe
category: Permissions
serialization:
can_load: true
can_save: true
- name: Instance.ClassName
summary: |
A read-only string representing the class this `Class.Instance` belongs
to.
description: |
A read-only string representing the class this `Class.Instance` belongs
to.
This property can be used with various other functions of Instance that
are used to identify objects by type, such as `Class.Instance:IsA()` or
`Class.Instance:FindFirstChildOfClass()`.
Note this property is read only and cannot be altered by scripts.
Developers wishing to change an instance's class will instead have to
create a new `Class.Instance`.
Unlike `Class.Instance: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
```
code_samples:
type: string
tags:
- ReadOnly
- NotReplicated
deprecation_message: ''
security:
read: None
write: None
thread_safety: ReadSafe
category: Data
serialization:
can_load: false
can_save: false
- name: Instance.Name
summary: |
A non-unique identifier of the `Class.Instance`.
description: |
A non-unique identifier of the `Class.Instance`.
This property is an identifier that describes an object. Names are not
necessarily unique identifiers however; multiple children of an object may
share the same name. Names are used to keep the object hierarchy
organized, along with allowing scripts to access specific objects. The
name of an 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 baseplate = workspace.Baseplate
local baseplate = workspace["Baseplate"]
local baseplate = workspace:FindFirstChild("BasePlate")
```
In order to make an object accessible using the dot operator, an object's
Name must follow a certain syntax. The objects name must start with an
underscore or letter. The rest of the name can only contain letters,
numbers, or underscores (no other special characters). If an objects name
does not follow this syntax it will not be accessible using the dot
operator and Lua will not interpret its name as an identifier.
If more than one object with the same name are siblings then any attempt
to index an object by that name will return the only one of the objects
found similar to `Class.Instance:FindFirstChild()`, but not always the
desired object. If a specific object needs to be accessed through code, it
is recommended to give it a unique name, or guarantee that none of its
siblings share the same name as it.
Note, a full name showing the instance's hierarchy can be obtained using
`Class.Instance:GetFullName()`.
code_samples:
type: string
tags: []
deprecation_message: ''
security:
read: None
write: None
thread_safety: ReadSafe
category: Data
serialization:
can_load: true
can_save: true
- 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** (**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 this property that many other API members get their name, such
as `Class.Instance:GetChildren()|GetChildren` and
`Class.Instance:FindFirstChild()|FindFirstChild`.
The `Class.Instance:Remove()|Remove` function sets this property to nil.
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.
This property is also used to manage whether an object exists in the game
or needs removed. As long as an objects parent is in the
`Class.DataModel`, is stored in a variable, or is referenced by another
objects property, then the object remains in the game. Otherwise, the
object will automatically be removed. The top level `Class.DataModel`
object (the one referred to as the `game` by scripts) has no parent, but
always has a reference held to it by the game engine, and exists for the
duration of a session.
Newly created objects using `Datatype.Instance.new()` will not have a
parent, and usually will not be visible or function until one is set. The
most elementary creation of an object has two steps: creating the object,
then setting its parent.
```
-- Create a part and parent it to the workspace
local part = Instance.new("Part")
part.Parent = workspace
-- Instance new can also take Parent as a second parameter
Instance.new("NumberValue", workspace)
```
When a change is made to certain properties while an instance is parented
in the `Class.DataModel`, the engine may need to perform extra work
internally (for things like replication, rendering, and GUI layout).
Whenever possible, change an instance's properties **before** you set its
Parent, rather than after, to avoid performing that work redundantly.
#### 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 then
setting many properties, it's recommended to **set Parent last**. This
ensures the object replicates once, instead of replicating many property
changes.
```lua
local part = Instance.new("Part") -- Avoid using the second parameter here
part.Anchored = true
part.BrickColor = BrickColor.new("Really red")
-- Potentially many other property changes could go here here...
-- Always set parent last!
part.Parent = workspace
```
However, if you were parenting your parts to a `Class.Model` whose parent
hasn't been set yet, then parenting each part to that model is okay as the
model would not have replicated yet.
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
- 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: bool
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
- name: Instance.Sandboxed
summary: ''
description: ''
code_samples: []
type: bool
tags:
- NotReplicated
deprecation_message: ''
security:
read: RobloxScriptSecurity
write: RobloxScriptSecurity
thread_safety: ReadSafe
category: Permissions
serialization:
can_load: false
can_save: false
- name: Instance.UniqueId
summary: ''
description: ''
code_samples: []
type: UniqueId
tags:
- NotReplicated
- NotScriptable
deprecation_message: ''
security:
read: RobloxSecurity
write: RobloxSecurity
thread_safety: ReadSafe
category: Data
serialization:
can_load: true
can_save: true
- name: Instance.archivable
summary: ''
description: ''
code_samples:
type: bool
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
- name: Instance.className
summary: ''
description: ''
code_samples:
type: string
tags:
- ReadOnly
- NotReplicated
- Deprecated
deprecation_message: |
This deprecated property is a variant of `Class.Instance.ClassName` which
should be used instead.
security:
read: None
write: None
thread_safety: ReadSafe
category: Data
serialization:
can_load: false
can_save: false
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.
Note that when tagging an instance, it's common that some resources are
used to give the tag its functionality, for example event connections or
tables. To prevent memory leaks, it's a good idea to clean these up
(disconnect, set to `nil`, etc.) when no longer needed for a tag. Do this
when calling `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: void
summary: ''
tags: []
deprecation_message: ''
security: None
thread_safety: Unsafe
- name: Instance:ClearAllChildren
summary: |
This function destroys all of an instance's children.
description: |
This function destroys all of an instance's children.
As `Class.Instance:Destroy()` also calls itself on the children of an
object it is used on, this function will destroy all descendants.
#### Alternatives to ClearAllChildren
If the developer does not wish to destroy all descendants, they should use
`Class.Instance:GetChildren()` or `Class.Instance:GetDescendants()` to
loop through an object and select what to destroy. For example, the
following code sample will destroy all parts in an object.
```
for _, instance in object:GetDescendants() do
if instance:IsA("BasePart") then
instance:Destroy()
end
end
```
code_samples:
- Instance-ClearAllChildren1
parameters: []
returns:
- type: void
summary: ''
tags: []
deprecation_message: ''
security: None
thread_safety: Unsafe
- 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 function 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 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 object 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
- 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 function is the correct way to dispose of
objects that are no longer required. Disposing of unneeded objects is
important, since unnecessary objects and connections in a place use up
memory (this is called a **memory leak**) which can lead to serious
performance issues over time.
**Tip:** After calling Destroy on an object, set any variables referencing
the object (or its descendants) to nil. This prevents your code from
accessing anything to do with the object.
```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, set `Class.Instance.Parent|Parent` it to nil
instead. For example:
```
object.Parent = nil
wait(2)
object.Parent = workspace
```
To Destroy an object after a set amount of time, use
`Class.Debris:AddItem()`.
code_samples:
- Instance-Destroy1
parameters: []
returns:
- type: void
summary: ''
tags: []
deprecation_message: ''
security: None
thread_safety: Unsafe
- 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 function 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 function 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
- name: Instance:FindFirstAncestorOfClass
summary: |
Returns the first ancestor of the `Class.Instance` whose
`Class.Instance.ClassName` is equal to the given className.
description: |
Returns the first ancestor of the `Class.Instance` whose
`Class.Instance.ClassName` is equal to the given className.
This function 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 function is finding the `Class.Model` a
`Class.BasePart` belongs to. For example:
```
local model = part:FindFirstAncestorOfClass("Model")
```
This function is a variant of `Class.Instance:FindFirstAncestor()` which
checks the `Class.Instance.ClassName` property rather than
`Class.Instance.Name`. `Class.Instance:FindFirstAncestorWhichIsA()` also
exists, using the `Class.Instance:IsA()` method instead to respect class
inheritance.
code_samples:
parameters:
- name: className
type: string
default:
summary: |
The `Class.Instance.ClassName` to be looked for.
returns:
- type: Instance
summary: |
The `Class.Instance` found.
tags: []
deprecation_message: ''
security: None
thread_safety: Safe
- name: Instance:FindFirstAncestorWhichIsA
summary: |
Returns the first ancestor of the `Class.Instance` for whom
`Class.Instance:IsA()` returns true for the given className.
description: |
Returns the first ancestor of the `Class.Instance` for whom
`Class.Instance:IsA()` returns true for the given className.
This function 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 function uses
`Class.Instance:IsA()` which respects class inheritance. For example:
```
print(part:IsA("Part")) --> true
print(part:IsA("BasePart")) --> true
print(part:IsA("Instance")) --> true
```
Therefore, the following code sample will return the first
`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.Instance.ClassName` to be looked for.
returns:
- type: Instance
summary: |
The `Class.Instance` found.
tags: []
deprecation_message: ''
security: None
thread_safety: Safe
- 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 function 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
-- The following line errors if Part doesn't exist in the Workspace:
workspace.Part.Transparency = 0.5
```
Use FindFirstChild to first check for Part, then use an if-statement to
run code that needs it.
```lua
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.
`Class.Part.Color` refers to the `Datatype.Color3`, not the Folder.
```lua
local part = Instance.new("Part")
local folder = Instance.new("Folder")
folder.Name = "Color"
folder.Parent = part
local c = part.Color --> A Color3
local c2 = part:FindFirstChild("Color") --> The Folder
```
A benefit of using `Class.Instance:FindFirstChild()|FindFirstChild()` in
this way is that the introduction of new properties does not impose a risk
on your code.
#### Performance Note
`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: bool
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
- name: Instance:FindFirstChildOfClass
summary: |
Returns the first child of the `Class.Instance` whose
`Class.Instance.ClassName|ClassName` is equal to the given className.
description: |
Returns the first child of the `Class.Instance` whose
`Class.Instance.ClassName|ClassName` is equal to the given className.
If no matching child is found, this function returns nil.
Unlike `Class.Instance:FindFirstChildWhichIsA()` this function uses only
returns objects whose class matches the given className, ignoring class
inheritance.
Developers looking for a child by name should use
`Class.Instance:FindFirstChild()` instead.
code_samples:
- Instance-FindFirstChildOfClass1
parameters:
- name: className
type: string
default:
summary: |
The `Class.Instance.ClassName` to be looked for.
returns:
- type: Instance
summary: |
The `Class.Instance` found.
tags: []
deprecation_message: ''
security: None
thread_safety: Safe
- name: Instance:FindFirstChildWhichIsA
summary: |
Returns the first child of the `Class.Instance` for whom
`Class.Instance:IsA()` returns true for the given className.
description: |
Returns the first child of the `Class.Instance` for whom
`Class.Instance:IsA()` returns true for the given className.
If no matching child is found, this function returns nil. If the optional
recursive argument is true, this function searches all descendants rather
than only the immediate children of the `Class.Instance`.
Unlike `Class.Instance:FindFirstChildOfClass()`, this function uses
`Class.Instance: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.Instance.ClassName` to be searched for.
- name: recursive
type: bool
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
- 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
- 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
- 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 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
- name: Instance:GetAttributeChangedSignal
summary: |
Returns an event that fires when the given attribute changes.
description: |
This function returns an event that behaves exactly like the
`Class.Instance.Changed|Changed` event, except that it only fires when the
specific given attribute changes; effectively it is similar to
`Class.Instance:GetPropertyChangedSignal()|GetPropertyChangedSignal()` but
for attributes.
It's generally a good idea to use this method instead of a connection to
`Class.Instance.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 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
- 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 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
- 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
-- Numeric for-loop example
local children = workspace:GetChildren()
for i = 1, #children do
local child = children[i]
print(child.Name .. " is child number " .. i)
end
```
```lua
-- Generic for-loop example
local children = workspace:GetChildren()
for i, child in children do
print(child.Name .. " is child number " .. i)
end
```
The children are sorted by the order in which their
`Class.Instance.Parent|Parent` property was set to the object.
See also the `Class.Instance:GetDescendants()|GetDescendants` function.
code_samples:
- Instance-GetChildren1
parameters: []
returns:
- type: Objects
summary: |
An array containing the instance's children.
tags: []
deprecation_message: ''
security: None
thread_safety: Safe
- 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:
- 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