File size: 92,425 Bytes
ef94a7c 1bc170b ef94a7c | 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 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 | Path
====
Not Creatable
Not Replicated
Path objects store the result of paths created by [PathfindingService:CreatePath()](/docs/reference/engine/classes/PathfindingService#CreatePath).
Once a path object is created, you can call [Path:ComputeAsync()](/docs/reference/engine/classes/Path#ComputeAsync) with a starting point and ending point. This will attempt to compute a valid path for a character to move along, based on default or custom parameters passed to [CreatePath()](/docs/reference/engine/classes/PathfindingService#CreatePath). If [ComputeAsync()](/docs/reference/engine/classes/Path#ComputeAsync) successfully finds a path, the [Path](/docs/reference/engine/classes/Path) object will have a [Path.Status](/docs/reference/engine/classes/Path#Status) value of [PathStatus.Success](/docs/reference/engine/enums/PathStatus#Success). Otherwise the status will be [PathStatus.NoPath](/docs/reference/engine/enums/PathStatus#NoPath) which can occur if there are obstacles between the two points (and no way around) or if the points are inside of solid objects.
In addition to [ComputeAsync()](/docs/reference/engine/classes/Path#ComputeAsync), [Path](/docs/reference/engine/classes/Path) objects have the [GetWaypoints()](/docs/reference/engine/classes/Path#GetWaypoints) method which returns a list of waypoints representing the points a character should follow in sequence to get from the beginning to the end of the path.
Finally, [Path](/docs/reference/engine/classes/Path) objects can be connected to the [Path.Blocked](/docs/reference/engine/classes/Path#Blocked) event. This event will fire if, at any time during the path's existence, the path is blocked. Note that this can occur behind a character moving along the path, not just in front of it.
Summary
-------
### Properties
[](#Status)Status: [PathStatus](/docs/reference/engine/enums/PathStatus)
The success of the generated [Path](/docs/reference/engine/classes/Path).
READ ONLY
NOT REPLICATED
Properties inherited from Instance
[](#Archivable)Archivable: [boolean](/docs/luau/booleans)
Determines if an [Instance](/docs/reference/engine/classes/Instance) can be cloned using [Instance:Clone()](/docs/reference/engine/classes/Instance#Clone) or saved to file.
[](#ClassName)ClassName: [string](/docs/luau/strings)
A read-only string representing the class this [Instance](/docs/reference/engine/classes/Instance) belongs to.
READ ONLY
NOT REPLICATED
[](#Name)Name: [string](/docs/luau/strings)
A non-unique identifier of the [Instance](/docs/reference/engine/classes/Instance).
[](#Parent)Parent: [Instance](/docs/reference/engine/classes/Instance)
Determines the hierarchical parent of the [Instance](/docs/reference/engine/classes/Instance).
NOT REPLICATED
[](#RobloxLocked)RobloxLocked: [boolean](/docs/luau/booleans)
A deprecated property that used to protect [CoreGui](/docs/reference/engine/classes/CoreGui) objects.
HIDDEN
[](#archivable)archivable: [boolean](/docs/luau/booleans)
HIDDEN
NOT REPLICATED
DEPRECATED
[](#className)className: [string](/docs/luau/strings)
READ ONLY
NOT REPLICATED
DEPRECATED
### Methods
[](#GetWaypoints)GetWaypoints(): [Array](/docs/luau/tables)
* * *
Returns an array of points in the path.
[](#CheckOcclusionAsync)CheckOcclusionAsync(start: [number](/docs/luau/numbers)): [number](/docs/luau/numbers) YIELDS
* * *
Checks if a path is blocked starting at a specific waypoint.
[](#ComputeAsync)ComputeAsync(start: [Vector3](/docs/reference/engine/datatypes/Vector3), finish: [Vector3](/docs/reference/engine/datatypes/Vector3)): void YIELDS
* * *
Computes a [Path](/docs/reference/engine/classes/Path) from a start position to an end position.
Methods inherited from Instance
[](#AddTag)AddTag(tag: [string](/docs/luau/strings)): void
* * *
Applies a tag to the instance.
[](#ClearAllChildren)ClearAllChildren(): void
* * *
This function destroys all of an [Instance](/docs/reference/engine/classes/Instance)'s children.
[](#Clone)Clone(): [Instance](/docs/reference/engine/classes/Instance)
* * *
Create a copy of an object and all its descendants, ignoring objects that are not [Archivable](/docs/reference/engine/classes/Instance#Archivable).
[](#Destroy)Destroy(): void
* * *
Sets the [Instance.Parent](/docs/reference/engine/classes/Instance#Parent) property to nil, locks the [Instance.Parent](/docs/reference/engine/classes/Instance#Parent) property, disconnects all connections, and calls Destroy on all children.
[](#FindFirstAncestor)FindFirstAncestor(name: [string](/docs/luau/strings)): [Instance](/docs/reference/engine/classes/Instance)
* * *
Returns the first ancestor of the [Instance](/docs/reference/engine/classes/Instance) whose [Instance.Name](/docs/reference/engine/classes/Instance#Name) is equal to the given name.
[](#FindFirstAncestorOfClass)FindFirstAncestorOfClass(className: [string](/docs/luau/strings)): [Instance](/docs/reference/engine/classes/Instance)
* * *
Returns the first ancestor of the [Instance](/docs/reference/engine/classes/Instance) whose [Instance.ClassName](/docs/reference/engine/classes/Instance#ClassName) is equal to the given className.
[](#FindFirstAncestorWhichIsA)FindFirstAncestorWhichIsA(className: [string](/docs/luau/strings)): [Instance](/docs/reference/engine/classes/Instance)
* * *
Returns the first ancestor of the [Instance](/docs/reference/engine/classes/Instance) for whom [Instance:IsA()](/docs/reference/engine/classes/Instance#IsA) returns true for the given className.
[](#FindFirstChild)FindFirstChild(name: [string](/docs/luau/strings), recursive: [boolean](/docs/luau/booleans)): [Instance](/docs/reference/engine/classes/Instance)
* * *
Returns the first child of the [Instance](/docs/reference/engine/classes/Instance) found with the given name.
[](#FindFirstChildOfClass)FindFirstChildOfClass(className: [string](/docs/luau/strings)): [Instance](/docs/reference/engine/classes/Instance)
* * *
Returns the first child of the [Instance](/docs/reference/engine/classes/Instance) whose [ClassName](/docs/reference/engine/classes/Instance#ClassName) is equal to the given className.
[](#FindFirstChildWhichIsA)FindFirstChildWhichIsA(className: [string](/docs/luau/strings), recursive: [boolean](/docs/luau/booleans)): [Instance](/docs/reference/engine/classes/Instance)
* * *
Returns the first child of the [Instance](/docs/reference/engine/classes/Instance) for whom [Instance:IsA()](/docs/reference/engine/classes/Instance#IsA) returns true for the given className.
[](#FindFirstDescendant)FindFirstDescendant(name: [string](/docs/luau/strings)): [Instance](/docs/reference/engine/classes/Instance)
* * *
Returns the first descendant found with the given [Instance.Name](/docs/reference/engine/classes/Instance#Name).
[](#GetActor)GetActor(): [Actor](/docs/reference/engine/classes/Actor)
* * *
Returns the [Actor](/docs/reference/engine/classes/Actor) associated with the Instance, if any.
[](#GetAttribute)GetAttribute(attribute: [string](/docs/luau/strings)): Variant
* * *
Returns the attribute which has been assigned to the given name.
[](#GetAttributeChangedSignal)GetAttributeChangedSignal(attribute: [string](/docs/luau/strings)): [RBXScriptSignal](/docs/reference/engine/datatypes/RBXScriptSignal)
* * *
Returns an event that fires when the given attribute changes.
[](#GetAttributes)GetAttributes(): [table](/docs/luau/tables)
* * *
Returns a dictionary of string → variant pairs for each of the [Instance](/docs/reference/engine/classes/Instance)'s attributes.
[](#GetChildren)GetChildren(): [Objects](/docs/luau/tuples)
* * *
Returns an array containing all of the [Instance](/docs/reference/engine/classes/Instance)'s children.
[](#GetDebugId)GetDebugId(scopeLength: [number](/docs/luau/numbers)): [string](/docs/luau/strings) NOT BROWSABLE
* * *
Returns a coded string of the [Instance](/docs/reference/engine/classes/Instance)s DebugId used internally by Roblox.
[](#GetDescendants)GetDescendants(): [Array](/docs/luau/tables) CUSTOM LUA STATE
* * *
Returns an array containing all of the descendants of the instance.
[](#GetFullName)GetFullName(): [string](/docs/luau/strings)
* * *
Returns a string describing the [Instance](/docs/reference/engine/classes/Instance)'s ancestry.
[](#GetPropertyChangedSignal)GetPropertyChangedSignal(property: [string](/docs/luau/strings)): [RBXScriptSignal](/docs/reference/engine/datatypes/RBXScriptSignal)
* * *
Get an event that fires when a given property of an object changes.
[](#GetTags)GetTags(): [Array](/docs/luau/tables)
* * *
Gets an array of all tags applied to the instance.
[](#HasTag)HasTag(tag: [string](/docs/luau/strings)): [boolean](/docs/luau/booleans)
* * *
Check whether the instance has a given tag.
[](#IsA)IsA(className: [string](/docs/luau/strings)): [boolean](/docs/luau/booleans) CUSTOM LUA STATE
* * *
Returns true if an [Instance](/docs/reference/engine/classes/Instance)'s class matches or inherits from a given class.
[](#IsAncestorOf)IsAncestorOf(descendant: [Instance](/docs/reference/engine/classes/Instance)): [boolean](/docs/luau/booleans)
* * *
Returns true if an [Instance](/docs/reference/engine/classes/Instance) is an ancestor of the given descendant.
[](#IsDescendantOf)IsDescendantOf(ancestor: [Instance](/docs/reference/engine/classes/Instance)): [boolean](/docs/luau/booleans)
* * *
Returns true if an [Instance](/docs/reference/engine/classes/Instance) is a descendant of the given ancestor.
[](#Remove)Remove(): void DEPRECATED
* * *
Sets the object's Parent to nil, and does the same for all its descendants.
[](#RemoveTag)RemoveTag(tag: [string](/docs/luau/strings)): void
* * *
Removes a tag from the instance.
[](#SetAttribute)SetAttribute(attribute: [string](/docs/luau/strings), value: Variant): void
* * *
Sets the attribute with the given name to the given value.
[](#WaitForChild)WaitForChild(childName: [string](/docs/luau/strings), timeOut: [number](/docs/luau/numbers)): [Instance](/docs/reference/engine/classes/Instance) CUSTOM LUA STATE, CAN YIELD
* * *
Returns the child of the [Instance](/docs/reference/engine/classes/Instance) with the given name. If the child does not exist, it will yield the current thread until it does.
[](#children)children(): [Objects](/docs/luau/tuples) DEPRECATED
* * *
Returns an array of the object's children.
[](#clone)clone(): [Instance](/docs/reference/engine/classes/Instance) DEPRECATED
* * *
[](#destroy)destroy(): void DEPRECATED
* * *
[](#findFirstChild)findFirstChild(name: [string](/docs/luau/strings), recursive: [boolean](/docs/luau/booleans)): [Instance](/docs/reference/engine/classes/Instance) DEPRECATED
* * *
[](#getChildren)getChildren(): [Objects](/docs/luau/tuples) DEPRECATED
* * *
[](#isA)isA(className: [string](/docs/luau/strings)): [boolean](/docs/luau/booleans) DEPRECATED, CUSTOM LUA STATE
* * *
[](#isDescendantOf)isDescendantOf(ancestor: [Instance](/docs/reference/engine/classes/Instance)): [boolean](/docs/luau/booleans) DEPRECATED
* * *
[](#remove)remove(): void DEPRECATED
* * *
### Events
[](#Blocked)Blocked(blockedWaypointIdx: [number](/docs/luau/numbers)): [RBXScriptSignal](/docs/reference/engine/datatypes/RBXScriptSignal)
* * *
Fires when the computed path becomes blocked.
[](#Unblocked)Unblocked(unblockedWaypointIdx: [number](/docs/luau/numbers)): [RBXScriptSignal](/docs/reference/engine/datatypes/RBXScriptSignal)
* * *
Fires when a computed path that was blocked becomes unblocked.
Events inherited from Instance
[](#AncestryChanged)AncestryChanged(child: [Instance](/docs/reference/engine/classes/Instance), parent: [Instance](/docs/reference/engine/classes/Instance)): [RBXScriptSignal](/docs/reference/engine/datatypes/RBXScriptSignal)
* * *
Fires when the [Instance.Parent](/docs/reference/engine/classes/Instance#Parent) property of the object or one of its ancestors is changed.
[](#AttributeChanged)AttributeChanged(attribute: [string](/docs/luau/strings)): [RBXScriptSignal](/docs/reference/engine/datatypes/RBXScriptSignal)
* * *
Fires whenever an attribute is changed on the [Instance](/docs/reference/engine/classes/Instance).
[](#Changed)Changed(property: [string](/docs/luau/strings)): [RBXScriptSignal](/docs/reference/engine/datatypes/RBXScriptSignal)
* * *
Fired immediately after a property of an object changes.
[](#ChildAdded)ChildAdded(child: [Instance](/docs/reference/engine/classes/Instance)): [RBXScriptSignal](/docs/reference/engine/datatypes/RBXScriptSignal)
* * *
Fires after an object is parented to this [Instance](/docs/reference/engine/classes/Instance).
[](#ChildRemoved)ChildRemoved(child: [Instance](/docs/reference/engine/classes/Instance)): [RBXScriptSignal](/docs/reference/engine/datatypes/RBXScriptSignal)
* * *
Fires after a child is removed from this [Instance](/docs/reference/engine/classes/Instance).
[](#DescendantAdded)DescendantAdded(descendant: [Instance](/docs/reference/engine/classes/Instance)): [RBXScriptSignal](/docs/reference/engine/datatypes/RBXScriptSignal)
* * *
Fires after a descendant is added to the [Instance](/docs/reference/engine/classes/Instance).
[](#DescendantRemoving)DescendantRemoving(descendant: [Instance](/docs/reference/engine/classes/Instance)): [RBXScriptSignal](/docs/reference/engine/datatypes/RBXScriptSignal)
* * *
Fires immediately before a descendant of the [Instance](/docs/reference/engine/classes/Instance) is removed.
[](#Destroying)Destroying(): [RBXScriptSignal](/docs/reference/engine/datatypes/RBXScriptSignal)
* * *
Fires immediately before the instance is destroyed via [Instance:Destroy()](/docs/reference/engine/classes/Instance#Destroy).
[](#childAdded)childAdded(child: [Instance](/docs/reference/engine/classes/Instance)): [RBXScriptSignal](/docs/reference/engine/datatypes/RBXScriptSignal) DEPRECATED
* * *
Properties
----------
### Status
[PathStatus](/docs/reference/engine/enums/PathStatus)
Read Only
Not Replicated
[Read Parallel](/docs/scripting/multithreading)
The success of the generated [Path](/docs/reference/engine/classes/Path).
Properties inherited from Instance
### Archivable
[boolean](/docs/luau/booleans)
[Read Parallel](/docs/scripting/multithreading)
This property determines whether an [object](/docs/reference/engine/classes/Instance) should be included when the game is published or saved, or when [Instance:Clone()](/docs/reference/engine/classes/Instance#Clone) is called on one of the object's ancestors. Calling Clone directly on an object will return nil if the cloned object is not archivable. Copying an object in Studio (using the 'Duplicate' or 'Copy' options) will ignore the Archivable property and set Archivable to true for the copy.
* * *
local part = Instance.new("Part")
print(part:Clone()) --> Part
part.Archivable = false
print(part:Clone()) --> nil
### ClassName
[string](/docs/luau/strings)
Read Only
Not Replicated
[Read Parallel](/docs/scripting/multithreading)
A read-only string representing the class this [Instance](/docs/reference/engine/classes/Instance) belongs to.
This property can be used with various other functions of Instance that are used to identify objects by type, such as [Instance:IsA()](/docs/reference/engine/classes/Instance#IsA) or [Instance:FindFirstChildOfClass()](/docs/reference/engine/classes/Instance#FindFirstChildOfClass).
Note this property is read only and cannot be altered by scripts. Developers wishing to change an [Instance](/docs/reference/engine/classes/Instance)'s class will instead have to create a new [Instance](/docs/reference/engine/classes/Instance).
Unlike [Instance:IsA()](/docs/reference/engine/classes/Instance#IsA), ClassName can be used to check if an object belongs to a specific class ignoring class inheritance. For example:
* * *
for _, child in ipairs(game.Workspace:GetChildren()) do
if child.ClassName == "Part" then
print("Found a Part")
-- will find Parts in model, but NOT TrussParts, WedgeParts, etc
end
end
### Name
[string](/docs/luau/strings)
[Read Parallel](/docs/scripting/multithreading)
A non-unique identifier of the [Instance](/docs/reference/engine/classes/Instance).
This property is an identifier that describes an object. Names are not necessarily unique identifiers however; multiple children of an object may share the same name. Names are used to keep the object hierarchy organized, along with allowing scripts to access specific objects.
The name of an object is often used to access the object through the data model hierarchy using the following methods:
* * *
local baseplate = workspace.Baseplate
local baseplate = workspace["Baseplate"]
local baseplate = workspace:FindFirstChild("BasePlate")
In order to make an object accessible using the dot operator, an object's Name must follow a certain syntax. The objects name must start with an underscore or letter. The rest of the name can only contain letters, numbers, or underscores (no other special characters). If an objects name does not follow this syntax it will not be accessible using the dot operator and Lua will not interpret its name as an identifier.
If more than one object with the same name are siblings then any attempt to index an object by that name will return the only one of the objects found similar to [Instance:FindFirstChild()](/docs/reference/engine/classes/Instance#FindFirstChild), but not always the desired object. If a specific object needs to be accessed through code, it is recommended to give it a unique name, or guarantee that none of its siblings share the same name as it.
Note, a full name showing the instance's hierarchy can be obtained using [Instance:GetFullName()](/docs/reference/engine/classes/Instance#GetFullName).
### Parent
[Instance](/docs/reference/engine/classes/Instance)
Not Replicated
[Read Parallel](/docs/scripting/multithreading)
The Parent property determines the hierarchical parent of the [Instance](/docs/reference/engine/classes/Instance). The following terminology is commonly used when talking about how this property is set:
* An object is a child (parented to) another object when its Parent is set to that object.
* The descendants of an [Instance](/docs/reference/engine/classes/Instance) are the children of that object, plus the descendants of the children as well.
* The ancestors of an [Instance](/docs/reference/engine/classes/Instance) are all the objects that the Instance is a descendant of.
It is from this property that many other API members get their name, such as [GetChildren](/docs/reference/engine/classes/Instance#GetChildren) and [FindFirstChild](/docs/reference/engine/classes/Instance#FindFirstChild).
The [Remove](/docs/reference/engine/classes/Instance#Remove) function sets this property to nil. Calling [Destroy](/docs/reference/engine/classes/Instance#Destroy) will set the Parent of an [Instance](/docs/reference/engine/classes/Instance) and all of its descendants to nil, and also lock the Parent property. An error is raised when setting the Parent of a destroyed object.
This property is also used to manage whether an object exists in the game or needs removed. As long as an objects parent is in the [DataModel](/docs/reference/engine/classes/DataModel), is stored in a variable, or is referenced by another objects property, then the object remains in the game. Otherwise, the object will automatically be removed. The top level [DataModel](/docs/reference/engine/classes/DataModel) object (the one referred to as the game by scripts) has no parent, but always has a reference held to it by the game engine, and exists for the duration of a session.
Newly created objects using [Instance.new()](/docs/reference/engine/datatypes/Instance#new) will not have a parent, and usually will not be visible or function until one is set. The most elementary creation of an object has two steps: creating the object, then setting its parent.
* * *
-- Create a part and parent it to the workspace
local part = Instance.new("Part")
part.Parent = workspace
-- Instance new can also take Parent as a second parameter
Instance.new("NumberValue", workspace)
#### Object Replication
An object created by server will not replicate to clients until it is parented to some object that is replicated. When creating an object then setting many properties, it's recommended to set Parent last. This ensures the object replicates once, instead of replicating many property changes.
* * *
local part = Instance.new("Part") -- Avoid using the second parameter here
part.Anchored = true
part.BrickColor = BrickColor.new("Really red")
-- Potentially many other property changes could go here here...
-- Always set parent last!
part.Parent = workspace
However, if you were parenting your parts to a [Model](/docs/reference/engine/classes/Model) whose parent hasn't been set yet, then setting the parent first would not matter as the model would not have replicated yet.
### RobloxLocked
[boolean](/docs/luau/booleans)
Hidden
Plugin Security
[Read Parallel](/docs/scripting/multithreading)
This property used to protect objects in the [CoreGui](/docs/reference/engine/classes/CoreGui) service from being altered by users in an unauthorized manner. It has been deprecated and does not do anything.
### archivable
[boolean](/docs/luau/booleans)
Hidden
Not Replicated
DEPRECATED
[Read Parallel](/docs/scripting/multithreading)
DEPRECATED
This deprecated property is a variant of [Instance.Archivable](/docs/reference/engine/classes/Instance#Archivable) which should be used instead.
### className
[string](/docs/luau/strings)
Read Only
Not Replicated
DEPRECATED
[Read Parallel](/docs/scripting/multithreading)
DEPRECATED
This deprecated property is a variant of [Instance.ClassName](/docs/reference/engine/classes/Instance#ClassName) which should be used instead.
Methods
-------
### GetWaypoints
[Array](/docs/luau/tables)
This function returns an array of all the [PathWaypoints](/docs/reference/engine/datatypes/PathWaypoint) in a [Path](/docs/reference/engine/classes/Path), as computed by [Path:ComputeAsync()](/docs/reference/engine/classes/Path#ComputeAsync).
Each waypoint in the array specifies a [Vector3](/docs/reference/engine/datatypes/Vector3) position and [action](/docs/reference/engine/enums/PathWaypointAction) to take when this PathWaypoint is reached. The array is arranged in the order of waypoints from the path start to path end.
If a path could not be computed, this function will return an empty array.
#### Returns
[Array](/docs/luau/tables)
An array of [PathWaypoints](/docs/reference/engine/datatypes/PathWaypoint) ordered from path start to path end.
#### Code Samples
The example below demonstrates how to create a Path and it's [PathWaypoints](/docs/reference/engine/datatypes/PathWaypoint) using the PathService.
It tries to [Path:ComputeAsync()](/docs/reference/engine/classes/Path#ComputeAsync) a path between two [Vector3](/docs/reference/engine/datatypes/Vector3) positions, from pathStart to pathEnd. If a path is successfully created, indicated by it's [PathStatus](/docs/reference/engine/enums/PathStatus), the code block gets an array of its waypoints using [Path:GetWaypoints()](/docs/reference/engine/classes/Path#GetWaypoints). Then, it loops through the array and prints each waypoint's position.
Get Path Waypoints
* * *
local PathfindingService = game:GetService("PathfindingService")
local path = PathfindingService:CreatePath()
local PATH_START = Vector3.new(0, 1, 0)
local PATH_END = Vector3.new(100, 1, 25)
path:ComputeAsync(PATH_START, PATH_END)
if path.Status == Enum.PathStatus.Success then
local waypoints = path:GetWaypoints()
for _, waypoint in pairs(waypoints) do
print(waypoint.Position)
end
end
### CheckOcclusionAsync
[number](/docs/luau/numbers)
Yields
This function checks if a path is blocked starting at the waypoint indicated by start.
It returns the first waypoint of occlusion if blocked, -1 if not. it returns an error if start is less than 0 or greater than the number of waypoints in the [Path](/docs/reference/engine/classes/Path).
#### Parameters
start: [number](/docs/luau/numbers)
#### Returns
[number](/docs/luau/numbers)
### ComputeAsync
void
Yields
This function computes a [Path](/docs/reference/engine/classes/Path) from a start position to an end position. This function is not automatically called when a path is created and must be invoked each time the path needs to be updated.
Once the Path is computed, it will have a series of waypoints that, when followed, can lead a character along the path. These points are gathered with the [Path:GetWaypoints()](/docs/reference/engine/classes/Path#GetWaypoints) function.
#### Parameters
start: [Vector3](/docs/reference/engine/datatypes/Vector3)
The world position where the computed path begins.
finish: [Vector3](/docs/reference/engine/datatypes/Vector3)
The world position where the computed path finishes.
#### Returns
void
#### Code Samples
The code sample below explores how to move an NPC along a more complex path or around obstacles. This is known as pathfinding.
Using the Pathfinding Service
* * *
local PathfindingService = game:GetService("PathfindingService")
local agentParams = {
AgentRadius = 2.0,
AgentHeight = 5.0,
AgentCanJump = false,
}
local currentWaypointIdx = 1
local path = PathfindingService:CreatePath(agentParams)
local humanoidRootPart = script.Parent:FindFirstChild("HumanoidRootPart")
local targetPosition = Vector3.new(50, 0, 50)
path:ComputeAsync(humanoidRootPart.Position, targetPosition)
-- When the path is blocked...
local function OnPathBlocked(blockedWaypointIdx)
-- Check if the obstacle is further down the path
if blockedWaypointIdx > currentWaypointIdx then
-- Recompute the path
path:ComputeAsync(humanoidRootPart.Position, targetPosition)
if path.Status == Enum.PathStatus.Success then
-- Retrieve update waypoint list with path:GetWaypoints()
-- and Continue walking towards target
else
-- Error, path not found
end
end
end
path.Blocked:Connect(OnPathBlocked)
Methods inherited from Instance
### AddTag
void
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 [CollectionService:GetInstanceAddedSignal()](/docs/reference/engine/classes/CollectionService#GetInstanceAddedSignal) with the given tag.
Note that when tagging an instance, it's common that some resources are used to give the tag its functionality, for example event connections or tables. To prevent memory leaks, it's a good idea to clean these up (disconnect, set to nil, etc.) when no longer needed for a tag. Do this when calling [Instance:RemoveTag()](/docs/reference/engine/classes/Instance#RemoveTag), calling [Instance:Destroy()](/docs/reference/engine/classes/Instance#Destroy), or in a function connected to a signal returned by [CollectionService:GetInstanceRemovedSignal()](/docs/reference/engine/classes/CollectionService#GetInstanceRemovedSignal).
#### Parameters
tag: [string](/docs/luau/strings)
#### Returns
void
### ClearAllChildren
void
This function destroys all of an [Instance](/docs/reference/engine/classes/Instance)'s children.
As [Instance:Destroy()](/docs/reference/engine/classes/Instance#Destroy) also calls itself on the children of an object it is used on, this function will destroy all descendants.
#### Alternatives to ClearAllChildren
If the developer does not wish to destroy all descendants, they should use [Instance:GetChildren()](/docs/reference/engine/classes/Instance#GetChildren) or [Instance:GetDescendants()](/docs/reference/engine/classes/Instance#GetDescendants) to loop through an object and select what to destroy. For example, the following code sample will destroy all parts in an object.
* * *
for _, instance in pairs(object:GetDescendants()) do
if instance:IsA("BasePart") then
instance:Destroy()
end
end
#### Returns
void
#### Code Samples
This example creates a Part and adds a few sparkle objects to the part. Then it calls Part:ClearAllChildren() to remove all of the children.
Instance:ClearAllChildren
* * *
local part = Instance.new("Part")
-- add some sparkles
for _ = 1, 3 do
local sparkles = Instance.new("Sparkles")
sparkles.Parent = part
end
print("Part has", #part:GetChildren(), "children")
--> Part has 3 children
part:ClearAllChildren()
print("Part has", #part:GetChildren(), "children")
--> Part has 0 children
### Clone
[Instance](/docs/reference/engine/classes/Instance)
Clone creates a copy of an object and all of its descendants, ignoring all objects that are not [Archivable](/docs/reference/engine/classes/Instance#Archivable). The copy of the root object is returned by this function and its [Parent](/docs/reference/engine/classes/Instance#Parent) is set to nil.
If a reference property such as [ObjectValue.Value](/docs/reference/engine/classes/ObjectValue#Value) is set in a cloned object, the value of the copy's property depends on original's value:
* If a reference property refers to an object that was also cloned, an _internal reference_, the copy will refer to the copy.
* If a reference property refers to an object that was not cloned, an _external reference_, the same value is maintained in the copy.
This function is typically used to create models that can be regenerated. First, get a reference to the original object. Then, make a copy of the object and insert the copy by setting its [Parent](/docs/reference/engine/classes/Instance#Parent) to the [Workspace](/docs/reference/engine/classes/Workspace) or one of its descendants. Finally, when it's time to regenerate the model, [Destroy](/docs/reference/engine/classes/Instance#Destroy) the copy and clone a new one from the original like before.
#### Returns
[Instance](/docs/reference/engine/classes/Instance)
#### Code Samples
This code first references an existing object in the original variable. Then, it makes a copy of the object, sets the parent to that of the original, and finally moves the copy to (0, 50, 0).
Clone Example
* * *
-- Get a reference to an existing object
local original = workspace.Model
-- Create the model copy
local copy = original:Clone()
-- Parent the copy to the same parent as the original
copy.Parent = original.Parent
-- Move the copy so it's not overlapping the original
copy:SetPrimaryPartCFrame(CFrame.new(0, 50, 0))
### Destroy
void
Sets the [Instance.Parent](/docs/reference/engine/classes/Instance#Parent) property to nil, locks the [Instance.Parent](/docs/reference/engine/classes/Instance#Parent) property, disconnects all connections, and calls Destroy on all children. This function is the correct way to dispose of objects that are no longer required. Disposing of unneeded objects is important, since unnecessary objects and connections in a place use up memory (this is called a memory leak) which can lead to serious performance issues over time.
Tip: After calling Destroy on an object, set any variables referencing the object (or its descendants) to nil. This prevents your code from accessing anything to do with the object.
* * *
local part = Instance.new("Part")
part.Name = "Hello, world"
part:Destroy()
-- Don't do this:
print(part.Name) --> "Hello, world"
-- Do this to prevent the above line from working:
part = nil
Once an [Instance](/docs/reference/engine/classes/Instance) has been destroyed by this method it cannot be reused because the [Instance.Parent](/docs/reference/engine/classes/Instance#Parent) property is locked. To temporarily remove an object, set [Parent](/docs/reference/engine/classes/Instance#Parent) it to nil instead. For example:
* * *
object.Parent = nil
wait(2)
object.Parent = workspace
To Destroy an object after a set amount of time, use [Debris:AddItem()](/docs/reference/engine/classes/Debris#AddItem).
#### Returns
void
#### Code Samples
Instance:Destroy
* * *
local Part = workspace.Part
Part:Destroy()
Part.Parent = workspace --> The Parent property of Part is locked
### FindFirstAncestor
[Instance](/docs/reference/engine/classes/Instance)
[Write Parallel](/docs/scripting/multithreading)
Returns the first ancestor of the [Instance](/docs/reference/engine/classes/Instance) whose [Instance.Name](/docs/reference/engine/classes/Instance#Name) is equal to the given name.
This function works upwards, meaning it starts at the [Instance](/docs/reference/engine/classes/Instance)'s immediate [Instance.Parent](/docs/reference/engine/classes/Instance#Parent) and works up towards the [DataModel](/docs/reference/engine/classes/DataModel). If no matching ancestor is found, it returns nil.
The following code snippet would find the first ancestor of the object named 'Car'.
* * *
local car = object:FindFirstAncestor("Car")
For variants of this function that find ancestors of a specific class, please see [Instance:FindFirstAncestorOfClass()](/docs/reference/engine/classes/Instance#FindFirstAncestorOfClass) and [Instance:FindFirstAncestorWhichIsA()](/docs/reference/engine/classes/Instance#FindFirstAncestorWhichIsA).
#### Parameters
name: [string](/docs/luau/strings)
The [Instance.Name](/docs/reference/engine/classes/Instance#Name) to be looked for.
#### Returns
[Instance](/docs/reference/engine/classes/Instance)
The [Instance](/docs/reference/engine/classes/Instance) found.
### FindFirstAncestorOfClass
[Instance](/docs/reference/engine/classes/Instance)
[Write Parallel](/docs/scripting/multithreading)
Returns the first ancestor of the [Instance](/docs/reference/engine/classes/Instance) whose [Instance.ClassName](/docs/reference/engine/classes/Instance#ClassName) is equal to the given className.
This function works upwards, meaning it starts at the [Instance](/docs/reference/engine/classes/Instance)'s immediate [Instance.Parent](/docs/reference/engine/classes/Instance#Parent) and works up towards the [DataModel](/docs/reference/engine/classes/DataModel). If no matching ancestor is found, it returns nil.
A common use of this function is finding the [Model](/docs/reference/engine/classes/Model) a [BasePart](/docs/reference/engine/classes/BasePart) belongs to. For example:
* * *
local model = part:FindFirstAncestorOfClass("Model")
This function is a variant of [Instance:FindFirstAncestor()](/docs/reference/engine/classes/Instance#FindFirstAncestor) which checks the [Instance.ClassName](/docs/reference/engine/classes/Instance#ClassName) property rather than [Instance.Name](/docs/reference/engine/classes/Instance#Name). [Instance:FindFirstAncestorWhichIsA()](/docs/reference/engine/classes/Instance#FindFirstAncestorWhichIsA) also exists, using the [Instance:IsA()](/docs/reference/engine/classes/Instance#IsA) method instead to respect class inheritance.
#### Parameters
className: [string](/docs/luau/strings)
The [Instance.ClassName](/docs/reference/engine/classes/Instance#ClassName) to be looked for.
#### Returns
[Instance](/docs/reference/engine/classes/Instance)
The [Instance](/docs/reference/engine/classes/Instance) found.
### FindFirstAncestorWhichIsA
[Instance](/docs/reference/engine/classes/Instance)
[Write Parallel](/docs/scripting/multithreading)
Returns the first ancestor of the [Instance](/docs/reference/engine/classes/Instance) for whom [Instance:IsA()](/docs/reference/engine/classes/Instance#IsA) returns true for the given className.
This function works upwards, meaning it starts at the [Instance](/docs/reference/engine/classes/Instance)'s immediate [Instance.Parent](/docs/reference/engine/classes/Instance#Parent) and works up towards the [DataModel](/docs/reference/engine/classes/DataModel). If no matching ancestor is found, it returns nil.
Unlike [Instance:FindFirstAncestorOfClass()](/docs/reference/engine/classes/Instance#FindFirstAncestorOfClass), this function uses [Instance:IsA()](/docs/reference/engine/classes/Instance#IsA) which respects class inheritance. For example:
* * *
print(part:IsA("Part")) --> true
print(part:IsA("BasePart")) --> true
print(part:IsA("Instance")) --> true
Therefore, the following code sample will return the first [BasePart](/docs/reference/engine/classes/BasePart) ancestor, regardless of if it is a [WedgePart](/docs/reference/engine/classes/WedgePart), [MeshPart](/docs/reference/engine/classes/MeshPart) or [Part](/docs/reference/engine/classes/Part).
* * *
local part = object:FindFirstAncestorWhichIsA("BasePart")
See also, [Instance:FindFirstAncestor()](/docs/reference/engine/classes/Instance#FindFirstAncestor).
#### Parameters
className: [string](/docs/luau/strings)
The [Instance.ClassName](/docs/reference/engine/classes/Instance#ClassName) to be looked for.
#### Returns
[Instance](/docs/reference/engine/classes/Instance)
The [Instance](/docs/reference/engine/classes/Instance) found.
### FindFirstChild
[Instance](/docs/reference/engine/classes/Instance)
[Write Parallel](/docs/scripting/multithreading)
Returns the first child of the [Instance](/docs/reference/engine/classes/Instance) with the given name,
or nil if no such child exists. If the optional recursive argument is true, this function searches all descendants rather than only the immediate children of the [Instance](/docs/reference/engine/classes/Instance).
#### Checking the Existence of an Object
FindFirstChild is necessary if you need to verify an object exists before continuing. Attempting to index a child by name using the dot operator throws an error if the child doesn't exist.
* * *
-- The following line errors if Part doesn't exist in the Workspace:
workspace.Part.Transparency = 0.5
Use FindFirstChild to first check for Part, then use an if-statement to run code that needs it.
* * *
local part = workspace:FindFirstChild("Part")
if part then
part.Transparency = 0.5
end
#### Finding a Child Whose Name Matches a Property
Sometimes the [Name](/docs/reference/engine/classes/Instance#Name) of an object is the same as that of a property of its [Parent](/docs/reference/engine/classes/Instance#Parent). When using the dot operator, properties take precedence over children if they share a name.
In the following example, a [Folder](/docs/reference/engine/classes/Folder) called "Color" is added to a [Part](/docs/reference/engine/classes/Part), which also has the [Part.Color](/docs/reference/engine/classes/Part#Color) property. [Part.Color](/docs/reference/engine/classes/Part#Color) refers to the [Color3](/docs/reference/engine/datatypes/Color3), not the Folder.
* * *
local part = Instance.new("Part")
local folder = Instance.new("Folder")
folder.Name = "Color"
folder.Parent = part
local c = part.Color --> A Color3
local c2 = part:FindFirstChild("Color") --> The Folder
A benefit of using [FindFirstChild()](/docs/reference/engine/classes/Instance#FindFirstChild) in this way is that the introduction of new properties does not impose a risk on your code.
#### Performance Note
[FindFirstChild()](/docs/reference/engine/classes/Instance#FindFirstChild) takes about 20% longer than using the dot operator and almost 8 times longer than simply storing a reference to an object. Therefore, you should avoid calling it in performance-dependent code such as in tight loops or functions connected to [RunService.Heartbeat](/docs/reference/engine/classes/RunService#Heartbeat) and [RunService.RenderStepped](/docs/reference/engine/classes/RunService#RenderStepped). Instead, store the result in a variable, or consider using [ChildAdded](/docs/reference/engine/classes/Instance#ChildAdded) or [WaitForChild()](/docs/reference/engine/classes/Instance#WaitForChild) to detect when a child of a given name becomes available.
#### Parameters
name: [string](/docs/luau/strings)
The [Instance.Name](/docs/reference/engine/classes/Instance#Name) to be searched for.
recursive: [boolean](/docs/luau/booleans)
Whether or not the search should be conducted recursively.
Default Value: false
#### Returns
[Instance](/docs/reference/engine/classes/Instance)
The [Instance](/docs/reference/engine/classes/Instance) found.
#### Code Samples
The below would look in Workspace for an object name "Brick". If found, it will change the name of the object to "Foo".
Instance:FindFirstChild
* * *
local found = workspace:FindFirstChild("Brick")
if found then
found.Name = "Foo"
end
### FindFirstChildOfClass
[Instance](/docs/reference/engine/classes/Instance)
[Write Parallel](/docs/scripting/multithreading)
Returns the first child of the [Instance](/docs/reference/engine/classes/Instance) whose [ClassName](/docs/reference/engine/classes/Instance#ClassName) is equal to the given className.
If no matching child is found, this function returns nil.
Unlike [Instance:FindFirstChildWhichIsA()](/docs/reference/engine/classes/Instance#FindFirstChildWhichIsA) this function uses only returns objects whose class matches the given className, ignoring class inheritance.
Developers looking for a child by name should use [Instance:FindFirstChild()](/docs/reference/engine/classes/Instance#FindFirstChild) instead.
#### Parameters
className: [string](/docs/luau/strings)
The [Instance.ClassName](/docs/reference/engine/classes/Instance#ClassName) to be looked for.
#### Returns
[Instance](/docs/reference/engine/classes/Instance)
The [Instance](/docs/reference/engine/classes/Instance) found.
#### Code Samples
Instance:FindFirstChildOfClass
* * *
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid
while not humanoid do
humanoid = character:FindFirstChildOfClass("Humanoid")
if not humanoid then
character.ChildAdded:Wait()
end
end
### FindFirstChildWhichIsA
[Instance](/docs/reference/engine/classes/Instance)
[Write Parallel](/docs/scripting/multithreading)
Returns the first child of the [Instance](/docs/reference/engine/classes/Instance) for whom [Instance:IsA()](/docs/reference/engine/classes/Instance#IsA) returns true for the given className.
If no matching child is found, this function returns nil. If the optional recursive argument is true, this function searches all descendants rather than only the immediate children of the [Instance](/docs/reference/engine/classes/Instance).
Unlike [Instance:FindFirstChildOfClass()](/docs/reference/engine/classes/Instance#FindFirstChildOfClass), this function uses [Instance:IsA()](/docs/reference/engine/classes/Instance#IsA) which respects class inheritance. For example:
* * *
print(part:IsA("Part")) --> true
print(part:IsA("BasePart")) --> true
print(part:IsA("Instance")) --> true
Therefore, the following code sample will return the first [BasePart](/docs/reference/engine/classes/BasePart) child, regardless of if it is a [WedgePart](/docs/reference/engine/classes/WedgePart), [MeshPart](/docs/reference/engine/classes/MeshPart) or [Part](/docs/reference/engine/classes/Part).
* * *
local part = object:FindFirstChildWhichIsA("BasePart")
Developers looking for a child by name, should use [Instance:FindFirstChild()](/docs/reference/engine/classes/Instance#FindFirstChild) instead.
#### Parameters
className: [string](/docs/luau/strings)
The [Instance.ClassName](/docs/reference/engine/classes/Instance#ClassName) to be searched for.
recursive: [boolean](/docs/luau/booleans)
Whether or not the search should be conducted recursively.
Default Value: false
#### Returns
[Instance](/docs/reference/engine/classes/Instance)
The [Instance](/docs/reference/engine/classes/Instance) found.
### FindFirstDescendant
[Instance](/docs/reference/engine/classes/Instance)
[Write Parallel](/docs/scripting/multithreading)
Returns the first descendant found with the given [Instance.Name](/docs/reference/engine/classes/Instance#Name).
#### Parameters
name: [string](/docs/luau/strings)
The [Instance.Name](/docs/reference/engine/classes/Instance#Name) to search for.
#### Returns
[Instance](/docs/reference/engine/classes/Instance)
The [Instance](/docs/reference/engine/classes/Instance) found.
### GetActor
[Actor](/docs/reference/engine/classes/Actor)
[Write Parallel](/docs/scripting/multithreading)
If the [Instance](/docs/reference/engine/classes/Instance) is an [Actor](/docs/reference/engine/classes/Actor), the [Actor](/docs/reference/engine/classes/Actor) itself is returned. Otherwise, its closest ancestor [Actor](/docs/reference/engine/classes/Actor) is returned. If no ancestor is an [Actor](/docs/reference/engine/classes/Actor), the result is nil.
#### Returns
[Actor](/docs/reference/engine/classes/Actor)
The [Actor](/docs/reference/engine/classes/Actor) found.
### GetAttribute
Variant
[Write Parallel](/docs/scripting/multithreading)
This function returns the attribute which has been assigned to the given name. If no attribute has been assigned then nil is returned.
For example, the following code snippet will set the value of the instance's InitialPostion attribute. Note that this code sample does not define [Instance](/docs/reference/engine/classes/Instance):
* * *
local initialPosition = instance:GetAttribute("InitialPosition")
See also:
* [Instance:SetAttribute()](/docs/reference/engine/classes/Instance#SetAttribute), sets the attribute with the given name to the given value
* [Instance:GetAttributes()](/docs/reference/engine/classes/Instance#GetAttributes), returns a dictionary of string → variant pairs for each of the instance's attributes
* [Instance.AttributeChanged](/docs/reference/engine/classes/Instance#AttributeChanged), fires whenever an attribute is changed on the instance
* [Instance:GetAttributeChangedSignal()](/docs/reference/engine/classes/Instance#GetAttributeChangedSignal), returns an event that fires when the given attribute changes
#### Parameters
attribute: [string](/docs/luau/strings)
The name of the attribute being retrieved.
#### Returns
Variant
The attribute which has been assigned to the given name. If no attribute has been assigned then nil is returned.
### GetAttributeChangedSignal
[RBXScriptSignal](/docs/reference/engine/datatypes/RBXScriptSignal)
This function returns an event that behaves exactly like the Changed event, except that the event only fires when the given attribute changes. It's generally a good idea to use this method instead of a connection to Changed with a function that checks the attribute name. Subsequent calls to this method on the same object with the same attribute name return the same event.
It is similar to [Instance:GetPropertyChangedSignal()](/docs/reference/engine/classes/Instance#GetPropertyChangedSignal) but for attributes.
For example, the following code snippet will return a signal that fires the function [Instance.AttributeChanged](/docs/reference/engine/classes/Instance#AttributeChanged) when the instance's InitialPosition attribute changes. Note that this code sample does not define [Instance](/docs/reference/engine/classes/Instance):
* * *
local function attributeChanged()
print("Attribute changed")
end
instance:GetAttributeChangedSignal("InitialPosition"):Connect(attributeChanged)
See also:
* [Instance:SetAttribute()](/docs/reference/engine/classes/Instance#SetAttribute), sets the attribute with the given name to the given value
* [Instance:GetAttribute()](/docs/reference/engine/classes/Instance#GetAttribute), returns the attribute which has been assigned to the given name
* [Instance:GetAttributes()](/docs/reference/engine/classes/Instance#GetAttributes), returns a dictionary of string → variant pairs for each of the instance's attributes
* [Instance.AttributeChanged](/docs/reference/engine/classes/Instance#AttributeChanged), fires whenever an attribute is changed on the instance
#### Parameters
attribute: [string](/docs/luau/strings)
The name of the specified attribute for which the change signal is being returned.
#### Returns
[RBXScriptSignal](/docs/reference/engine/datatypes/RBXScriptSignal)
An event that fires when the given attribute changes.
### GetAttributes
[table](/docs/luau/tables)
[Write Parallel](/docs/scripting/multithreading)
This function returns a dictionary of string → variant pairs for each attribute where the string is the name of the attribute and the variant is a non-nil value.
For example, the following code snippet will print an instance's attributes and values. Note that this code sample does not define [Instance](/docs/reference/engine/classes/Instance):
* * *
local attributes = instance:GetAttributes()
for name, value in pairs(attributes) do
print(name .. " " .. value)
end
See also:
* [Instance:SetAttribute()](/docs/reference/engine/classes/Instance#SetAttribute), sets the attribute with the given name to the given value
* [Instance:GetAttribute()](/docs/reference/engine/classes/Instance#GetAttribute), returns the attribute which has been assigned to the given name
* [Instance.AttributeChanged](/docs/reference/engine/classes/Instance#AttributeChanged), fires whenever an attribute is changed on the instance
* [Instance:GetAttributeChangedSignal()](/docs/reference/engine/classes/Instance#GetAttributeChangedSignal), returns an event that fires when the given attribute changes
#### Returns
[table](/docs/luau/tables)
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.
### GetChildren
[Objects](/docs/luau/tuples)
[Write Parallel](/docs/scripting/multithreading)
Returns an array (a numerically indexed table) containing all of the [Instance](/docs/reference/engine/classes/Instance)'s direct children, or every [Instance](/docs/reference/engine/classes/Instance) whose [Parent](/docs/reference/engine/classes/Instance#Parent) is equal to the object. The array can be iterated upon using either a numeric or generic for-loop:
* * *
-- Numeric for-loop example
local children = workspace:GetChildren()
for i = 1, #children do
local child = children[i]
print(child.Name .. " is child number " .. i)
end
* * *
-- Generic for-loop example
local children = workspace:GetChildren()
for i, child in ipairs(children) do
print(child.Name .. " is child number " .. i)
end
The children are sorted by the order in which their [Parent](/docs/reference/engine/classes/Instance#Parent) property was set to the object.
See also the [GetDescendants](/docs/reference/engine/classes/Instance#GetDescendants) function.
#### Returns
[Objects](/docs/luau/tuples)
An array containing the [Instance](/docs/reference/engine/classes/Instance)'s children.
#### Code Samples
The below would print the name of all objects currently in Workspace when ran.
Instance:GetChildren
* * *
local children = workspace:GetChildren()
for i = 1, #children do
print(i, children[i].Name)
end
### GetDebugId
[string](/docs/luau/strings)
Not Browsable
Plugin Security
Returns a coded string of the [Instance](/docs/reference/engine/classes/Instance)s DebugId used internally by Roblox.
Note:
* This item is protected. Attempting to use it in a [Script](/docs/reference/engine/classes/Script) or [LocalScript](/docs/reference/engine/classes/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)
#### Parameters
scopeLength: [number](/docs/luau/numbers)
The scope length.
Default Value: 4
#### Returns
[string](/docs/luau/strings)
The Debug ID string.
#### Code Samples
Instance:GetDebugId
* * *
print(workspace:GetDebugId()) --> 39FA_12
print(workspace:GetDebugId(10)) --> 39FA2FEF4D_12
print(workspace:GetDebugId(math.huge)) --> 12
### GetDescendants
[Array](/docs/luau/tables)
Custom Lua State
[Write Parallel](/docs/scripting/multithreading)
The GetDescendants function of an object returns an array that contains all of the descendants of that object. Unlike [Instance:GetChildren()](/docs/reference/engine/classes/Instance#GetChildren), which only returns the immediate children of an object, GetDescendants will find every child of the object, every child of those children, and so on.
The arrays returned by GetDescendants are arranged so that parents come earlier than their children. Refer to the following example of a [Model](/docs/reference/engine/classes/Model) in the [Workspace](/docs/reference/engine/classes/Workspace):

Inside this model are three parts (C, D, and E) and another model (InnerModel). Inside the inner model are two more parts (A and B). Calling GetDescendants on the first model and printing the contents of the returned array would print the first level of children (InnerModel, C, D, and E) before A and B.
* * *
local descendants = game.Workspace.Model:GetDescendants()
-- Loop through all of the descendants of the model and
-- print out their name
for index, descendant in pairs(descendants) do
print(descendant.Name)
end
-- Prints:
-- C
-- D
-- E
-- InnerModel
-- A
-- B
#### Returns
[Array](/docs/luau/tables)
An array containing the [Instance](/docs/reference/engine/classes/Instance)'s descendants.
#### Code Samples
GetDescendants is often used to do something to all the descendants that are a particular type of object. The code in this example uses GetDescendants and [Instance:IsA()](/docs/reference/engine/classes/Instance#IsA) to find all of the parts in the workspace and turns them green.
Instance:GetDescendants
* * *
local descendants = workspace:GetDescendants()
-- Loop through all of the descendants of the Workspace. If a
-- BasePart is found, the code changes that parts color to green
for _, descendant in pairs(descendants) do
if descendant:IsA("BasePart") then
descendant.BrickColor = BrickColor.Green()
end
end
### GetFullName
[string](/docs/luau/strings)
[Write Parallel](/docs/scripting/multithreading)
Returns a string describing the [Instance](/docs/reference/engine/classes/Instance)'s ancestry. The string is a concatenation of the [Name](/docs/reference/engine/classes/Instance#Name) of the object and its ancestors, separated by periods. The [DataModel](/docs/reference/engine/classes/DataModel) (game) is not considered. For example, a [Part](/docs/reference/engine/classes/Part) in the [Workspace](/docs/reference/engine/classes/Workspace) may return [Workspace.Part](/docs/reference/engine/classes/Workspace#Part).
When called on an [Instance](/docs/reference/engine/classes/Instance) that is not a descendant of the [DataModel](/docs/reference/engine/classes/DataModel), this function considers all ancestors up to and including the topmost one without a [Parent](/docs/reference/engine/classes/Instance#Parent).
This function is useful for logging and debugging. You shouldn't attempt to parse the returned string for any useful operation; this function does not escape periods (or any other symbol) in object names. In other words, although its output often appears to be a valid Lua identifier, it is not guaranteed.
#### Returns
[string](/docs/luau/strings)
The full name of the [Instance](/docs/reference/engine/classes/Instance).
#### Code Samples
This code sample demonstrates the behavior of [Instance:GetFullName()](/docs/reference/engine/classes/Instance#GetFullName). It shows how the function behaves when called on an object not in the DataModel hierarchy, and it also shows how the return value does not escape special characters.
Instance:GetFullName
* * *
-- Create a simple hierarchy
local model = Instance.new("Model")
local part = Instance.new("Part")
part.Parent = model
local fire = Instance.new("Fire")
fire.Parent = part
print(fire:GetFullName()) --> Model.Part.Fire
model.Parent = workspace
print(fire:GetFullName()) --> Workspace.Model.Part.Fire
part.Name = "Hello, world"
print(fire:GetFullName()) --> Workspace.Model.Hello, world.Fire
This code sample re-implements the [Instance:GetFullName()](/docs/reference/engine/classes/Instance#GetFullName) function in Lua.
Instance:GetFullName Lua Implementation
* * *
local function getFullName(object)
local result = object.Name
object = object.Parent
while object and object ~= game do
-- Prepend parent name
result = object.Name .. "." .. result
-- Go up the hierarchy
object = object.Parent
end
return result
end
print(getFullName(workspace.Camera)) --> Workspace.Camera
### GetPropertyChangedSignal
[RBXScriptSignal](/docs/reference/engine/datatypes/RBXScriptSignal)
This method returns an event that behaves exactly like the Changed event, except that the event only fires when the given property changes. It's generally a good idea to use this method instead of a connection to Changed with a function that checks the property name. Subsequent calls to this method on the same object with the same property name return the same event.
print(object:GetPropertyChangedSignal("Name") == object:GetPropertyChangedSignal("Name")) --> always true
[ValueBase](/docs/reference/engine/classes/ValueBase) objects, such as [IntValue](/docs/reference/engine/classes/IntValue) and [StringValue](/docs/reference/engine/classes/StringValue), use a modified Changed event that fires with the contents of the Value property. As such, this method provides a way to detect changes in other properties of those objects. For example, to detect changes in the Name property of an [IntValue](/docs/reference/engine/classes/IntValue), use IntValue:GetPropertyChangedSignal("Name"):Connect(someFunc) since the Changed event of [IntValue](/docs/reference/engine/classes/IntValue) objects only detect changes on the Value property.
#### Parameters
property: [string](/docs/luau/strings)
The property to connect to.
#### Returns
[RBXScriptSignal](/docs/reference/engine/datatypes/RBXScriptSignal)
A signal that fires whenever the property changes.
#### Code Samples
This code sample demonstrates how to save a value before a changed event fires on it in order to get more information about a change.
Old-to-New Values with Changed
* * *
local part = Instance.new("Part")
local currentColor = part.BrickColor
local function onBrickColorChanged()
local newColor = part.BrickColor
print("Color changed from", currentColor.Name, "to", newColor.Name)
currentColor = newColor
end
part:GetPropertyChangedSignal("BrickColor"):Connect(onBrickColorChanged)
part.BrickColor = BrickColor.new("Really red")
part.BrickColor = BrickColor.new("Really blue")
This code sample demonstrates the equivalence of the Changed event and event returned by GetPropertyChangedSignal.
Changed and GetPropertyChangedSignal
* * *
local part = Instance.new("Part")
local function onBrickColorChanged()
print("My color is now " .. part.BrickColor.Name)
end
local function onChanged(property)
if property == "BrickColor" then
onBrickColorChanged()
end
end
part:GetPropertyChangedSignal("BrickColor"):Connect(onBrickColorChanged)
part.Changed:Connect(onChanged)
-- Trigger some changes (because we connected twice,
-- both of these will cause two calls to onBrickColorChanged)
part.BrickColor = BrickColor.new("Really red")
part.BrickColor = BrickColor.new("Institutional white")
### GetTags
[Array](/docs/luau/tables)
[Write Parallel](/docs/scripting/multithreading)
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](https://prod.docsiteassets.roblox.com/studio/properties.md) window or at runtime with [AddTag()](/docs/reference/engine/classes/Instance#AddTag).
This method is useful when you want to do something with multiple tags on an instance at once. However, it is inefficient to use this method to check for the existence of a single tag; instead, use [HasTag()](/docs/reference/engine/classes/Instance#HasTag) to check for a specific tag.
#### Returns
[Array](/docs/luau/tables)
### HasTag
[boolean](/docs/luau/booleans)
[Write Parallel](/docs/scripting/multithreading)
This method returns true if the provided tag has been added to the object. You can add tags either in Studio in the [Properties](https://prod.docsiteassets.roblox.com/studio/properties.md) window or at runtime with [AddTag()](/docs/reference/engine/classes/Instance#AddTag).
#### Parameters
tag: [string](/docs/luau/strings)
#### Returns
[boolean](/docs/luau/booleans)
### IsA
[boolean](/docs/luau/booleans)
Custom Lua State
[Write Parallel](/docs/scripting/multithreading)
IsA returns true if the [Instance](/docs/reference/engine/classes/Instance)'s class is equivalent to or a subclass of a given class. This function is similar to the instanceof operators in other languages, and is a form of [type introspection](https://en.wikipedia.org/wiki/Type_introspection). To ignore class inheritance, test the [ClassName](/docs/reference/engine/classes/Instance#ClassName) property directly instead. For checking native Lua data types (number, string, etc) use the functions type and typeof.
Most commonly, this function is used to test if an object is some kind of part, such as [Part](/docs/reference/engine/classes/Part) or [WedgePart](/docs/reference/engine/classes/WedgePart), which inherits from [BasePart](/docs/reference/engine/classes/BasePart) (an abstract class). For example, if your goal is to change all of a [Character](/docs/reference/engine/classes/Player#Character)'s limbs to the same color, you might use [GetChildren](/docs/reference/engine/classes/Instance#GetChildren) to iterate over the children, then use IsA to filter non-[BasePart](/docs/reference/engine/classes/BasePart) objects which lack the [BrickColor](/docs/reference/engine/datatypes/BrickColor) property:
* * *
local function paintFigure(character, color)
-- Iterate over the child objects of the character
for _, child in pairs(character:GetChildren()) do
-- Filter out non-part objects, such as Shirt, Pants and Humanoid
-- R15 use MeshPart and R6 use Part, so we use BasePart here to detect both:
if child:IsA("BasePart") then
child.BrickColor = color
end
end
end
paintFigure(game.Players.Player.Character, BrickColor.new("Bright blue"))
Since all classes inherit from [Instance](/docs/reference/engine/classes/Instance), calling object:IsA("Instance") will always return true.
#### Parameters
className: [string](/docs/luau/strings)
The class against which the Instance's class will be checked. Case-sensitive.
#### Returns
[boolean](/docs/luau/booleans)
Describes whether the Instance's class matched or is a subclass of the given class.
#### Code Samples
Usage of IsA to test class inheritance:
Instance:IsA
* * *
print(workspace:IsA("Instance")) --> true
print(workspace:IsA("Workspace")) --> true
print(game:IsA("workspace")) --> false
print(game:IsA("DataModel")) --> true
### IsAncestorOf
[boolean](/docs/luau/booleans)
[Write Parallel](/docs/scripting/multithreading)
Returns true if an [Instance](/docs/reference/engine/classes/Instance) is an ancestor of the given descendant.
An [Instance](/docs/reference/engine/classes/Instance) is considered the ancestor of an object if the object's [Instance.Parent](/docs/reference/engine/classes/Instance#Parent) or one of it's parent's [Instance.Parent](/docs/reference/engine/classes/Instance#Parent) is set to the [Instance](/docs/reference/engine/classes/Instance).
See also, [Instance:IsDescendantOf()](/docs/reference/engine/classes/Instance#IsDescendantOf).
#### Parameters
descendant: [Instance](/docs/reference/engine/classes/Instance)
The descendant [Instance](/docs/reference/engine/classes/Instance).
#### Returns
[boolean](/docs/luau/booleans)
True if the [Instance](/docs/reference/engine/classes/Instance) is an ancestor of the given descendant.
#### Code Samples
Instance:IsAncestorOf
* * *
print(workspace:IsAncestorOf(workspace.Player.HumanoidRootPart)) --> true
### IsDescendantOf
[boolean](/docs/luau/booleans)
[Write Parallel](/docs/scripting/multithreading)
Returns true if an [Instance](/docs/reference/engine/classes/Instance) is a descendant of the given ancestor.
An [Instance](/docs/reference/engine/classes/Instance) is considered the descendant of an object if the [Instance](/docs/reference/engine/classes/Instance)'s parent or one of its parent's parent is set to the object.
Note, [DataModel](/docs/reference/engine/classes/DataModel) is a descendant of nil. This means IsDescendantOf cannot be used with a parameter of nil to check if an object has been removed.
See also, [Instance:IsAncestorOf()](/docs/reference/engine/classes/Instance#IsAncestorOf).
#### Parameters
ancestor: [Instance](/docs/reference/engine/classes/Instance)
The ancestor [Instance](/docs/reference/engine/classes/Instance).
#### Returns
[boolean](/docs/luau/booleans)
True if the [Instance](/docs/reference/engine/classes/Instance) is a descendant of the given ancestor.
#### Code Samples
Instance:IsDescendantOf
* * *
local part = Instance.new("Part")
print(part:IsDescendantOf(game))
--> false
part.Parent = workspace
print(part:IsDescendantOf(game))
--> true
part.Parent = game
print(part:IsDescendantOf(game))
--> true
### Remove
void
DEPRECATED
DEPRECATED
This item is deprecated in favor of [Instance:Destroy()](/docs/reference/engine/classes/Instance#Destroy) and [Instance:ClearAllChildren()](/docs/reference/engine/classes/Instance#ClearAllChildren). If you must remove an object from the game, and wish to use the object later, set its Parent property to nil instead of using this method.
The Remove function sets the object's [Instance.Parent](/docs/reference/engine/classes/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.
#### Returns
void
#### Code Samples
The following code demonstrates how a part can be re-added to the DataModel after being removed:
Instance:Remove
* * *
local part = Instance.new("Part")
part.Parent = workspace
print(part.Parent) --> Workspace
part:Remove()
print(part.Parent) --> nil
part.Parent = workspace
print(part.Parent) --> Workspace
### RemoveTag
void
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 [CollectionService:GetInstanceRemovedSignal()](/docs/reference/engine/classes/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.
#### Parameters
tag: [string](/docs/luau/strings)
#### Returns
void
### SetAttribute
void
This function sets the attribute with the given name to the given value. If the value given is nil, then the attribute will be removed (since nil is returned by default).
For example, the following code snippet will set the instance's InitialPosition attribute to [Vector3.new(0, 0, 0)](/docs/reference/engine/datatypes/Vector3). Note that this code sample does not define [Instance](/docs/reference/engine/classes/Instance):
* * *
instance:SetAttribute("InitialPosition", Vector3.new(0, 0, 0))
#### Limitations
Naming requirements and restrictions:
* Names must only use alphanumeric characters and underscore
* No spaces or unique symbols are allowed
* Strings must be 100 characters or less
* Names are not allowed to start with RBX unless the caller is a Roblox core-script (reserved for Roblox)
When attempting to set an attribute to an unsupported type, an error will be thrown.
See also:
* [Instance:GetAttribute()](/docs/reference/engine/classes/Instance#GetAttribute), returns the attribute which has been assigned to the given name
* [Instance:GetAttributes()](/docs/reference/engine/classes/Instance#GetAttributes), returns a dictionary of string → variant pairs for each of the instance's attributes
* [Instance.AttributeChanged](/docs/reference/engine/classes/Instance#AttributeChanged), fires whenever an attribute is changed on the instance
* [Instance:GetAttributeChangedSignal()](/docs/reference/engine/classes/Instance#GetAttributeChangedSignal), returns an event that fires when the given attribute changes
#### Parameters
attribute: [string](/docs/luau/strings)
The name of the attribute being set.
value: Variant
The value that the specified attribute is being set to.
#### Returns
void
### WaitForChild
[Instance](/docs/reference/engine/classes/Instance)
Custom Lua State
Can Yield
Returns the child of the [Instance](/docs/reference/engine/classes/Instance) with the given name. If the child does not exist, it will yield the current thread until it does. If the timeOut parameter is specified, this method will time out after the specified number of seconds and return nil.
#### Primary Usage
[WaitForChild()](/docs/reference/engine/classes/Instance#WaitForChild) is extremely important when working on code run by the client in a [LocalScript](/docs/reference/engine/classes/LocalScript). The Roblox engine does not guarantee the time or order in which objects are replicated from the server to the client. Additionally, if an experience has [Workspace.StreamingEnabled](/docs/reference/engine/classes/Workspace#StreamingEnabled) set to true, [BaseParts](/docs/reference/engine/classes/BasePart) that are far away from the player's character may not be streamed to the client, potentially causing scripts to break when indexing objects that do not yet exist on the client.
#### Notes
* This function does not yield if a child with the given name exists when the call is made.
* [Instance:FindFirstChild()](/docs/reference/engine/classes/Instance#FindFirstChild) is a more efficient alternative to [WaitForChild()](/docs/reference/engine/classes/Instance#WaitForChild) for objects that are assumed to exist.
* If a call to this method exceeds 5 seconds without returning, and no timeOut parameter has been specified, a warning will be printed to the output that the thread may yield indefinitely. This warning takes the following form where X is the parent's name and Y is the child's name:
Infinite yield possible on 'X:WaitForChild("Y")'
#### Parameters
childName: [string](/docs/luau/strings)
The [Instance.Name](/docs/reference/engine/classes/Instance#Name) to be looked for.
timeOut: [number](/docs/luau/numbers)
An optional time out parameter.
#### Returns
[Instance](/docs/reference/engine/classes/Instance)
The [Instance](/docs/reference/engine/classes/Instance) found.
#### Code Samples
The following code waits for an instance named "Part" to be added to Workspace.
Instance:WaitForChild
* * *
local part = workspace:WaitForChild("Part")
print(part.Name .. " has been added to the Workspace")
### children
[Objects](/docs/luau/tuples)
DEPRECATED
DEPRECATED
This item has been superseded by [Instance:GetChildren()](/docs/reference/engine/classes/Instance#GetChildren) which should be used in all new work.
The children function returns an array of the object's children.
#### Returns
[Objects](/docs/luau/tuples)
Array of child objects/instances.
### clone
[Instance](/docs/reference/engine/classes/Instance)
DEPRECATED
DEPRECATED
This deprecated function is a variant of [Instance:Clone()](/docs/reference/engine/classes/Instance#Clone) which should be used instead.
#### Returns
[Instance](/docs/reference/engine/classes/Instance)
### destroy
void
DEPRECATED
DEPRECATED
This deprecated function is a variant of [Instance:Destroy()](/docs/reference/engine/classes/Instance#Destroy) which should be used instead.
#### Returns
void
### findFirstChild
[Instance](/docs/reference/engine/classes/Instance)
DEPRECATED
DEPRECATED
This deprecated function is a variant of [Instance:FindFirstChild()](/docs/reference/engine/classes/Instance#FindFirstChild) which should be used instead.
#### Parameters
name: [string](/docs/luau/strings)
recursive: [boolean](/docs/luau/booleans)
Default Value: false
#### Returns
[Instance](/docs/reference/engine/classes/Instance)
### getChildren
[Objects](/docs/luau/tuples)
DEPRECATED
DEPRECATED
This deprecated function is a variant of [Instance:GetChildren()](/docs/reference/engine/classes/Instance#GetChildren) which should be used instead.
#### Returns
[Objects](/docs/luau/tuples)
### isA
[boolean](/docs/luau/booleans)
DEPRECATED
Custom Lua State
DEPRECATED
This deprecated function is a variant of [Instance:IsA()](/docs/reference/engine/classes/Instance#IsA) which should be used instead.
#### Parameters
className: [string](/docs/luau/strings)
#### Returns
[boolean](/docs/luau/booleans)
### isDescendantOf
[boolean](/docs/luau/booleans)
DEPRECATED
DEPRECATED
This deprecated function is a variant of [Instance:IsDescendantOf()](/docs/reference/engine/classes/Instance#IsDescendantOf) which should be used instead.
#### Parameters
ancestor: [Instance](/docs/reference/engine/classes/Instance)
#### Returns
[boolean](/docs/luau/booleans)
### remove
void
DEPRECATED
DEPRECATED
This deprecated function is a variant of [Instance:Remove()](/docs/reference/engine/classes/Instance#Remove) which has also been deprecated. Neither function should be used in new work.
#### Returns
void
Events
------
### Blocked
Fires when the computed path becomes blocked. Note that paths may become blocked somewhere behind the agent, such as a pile of rubble falling on a path as the agent runs away. See [Handling Blocked Paths](/docs/characters/pathfinding#handling-blocked-paths) for details on checking the forward waypoint progress of an agent along a path.
#### Parameters
blockedWaypointIdx: [number](/docs/luau/numbers)
### Unblocked
Fires when a computed path that was blocked becomes unblocked. Note that a blocked path may become unblocked somewhere behind the agent, effectively making reaction to this event unnecessary. See [Handling Blocked Paths](/docs/characters/pathfinding#handling-blocked-paths) for details on checking the forward waypoint progress of an agent along a path.
#### Parameters
unblockedWaypointIdx: [number](/docs/luau/numbers)
Events inherited from Instance
### AncestryChanged
Fires when the [Instance.Parent](/docs/reference/engine/classes/Instance#Parent) property of the object or one of its ancestors is changed.
This event includes two parameters, _child_ and _parent_. _Child_ refers to the [Instance](/docs/reference/engine/classes/Instance) whose [Instance.Parent](/docs/reference/engine/classes/Instance#Parent) was actually changed. _Parent_ refers to this [Instance](/docs/reference/engine/classes/Instance)'s new [Instance.Parent](/docs/reference/engine/classes/Instance#Parent).
You can use this event to track the deletion of an instance in Studio, such as manual deletion in the Explorer or through a plugin. If you need to detect when an instance is destroyed using [Instance:Destroy()](/docs/reference/engine/classes/Instance#Destroy), use the [Instance.Destroying](/docs/reference/engine/classes/Instance#Destroying) event instead.
#### Parameters
child: [Instance](/docs/reference/engine/classes/Instance)
The [Instance](/docs/reference/engine/classes/Instance) whose [Instance.Parent](/docs/reference/engine/classes/Instance#Parent) has been changed.
parent: [Instance](/docs/reference/engine/classes/Instance)
The new [Instance.Parent](/docs/reference/engine/classes/Instance#Parent) of the [Instance](/docs/reference/engine/classes/Instance) whose [Instance.Parent](/docs/reference/engine/classes/Instance#Parent) was changed.
#### Code Samples
The below example would print "Part is now a child of Model".
Instance.AncestryChanged
* * *
local part = Instance.new("Part")
part.Parent = workspace
local function onAncestryChanged(child, parent)
print(child.Name .. " is now a child of " .. parent.Name)
end
part.AncestryChanged:Connect(onAncestryChanged)
part.Parent = workspace.Model
### AttributeChanged
This event fires whenever an attribute is changed on the instance. This includes when an attribute is set to nil. The name of the attribute that has been changed is passed to the connected function.
For example, the following code snippet will connect the AttributeChanged function to fire whenever one of [Instance](/docs/reference/engine/classes/Instance)'s attributes changes. Note that this code sample does not define [Instance](/docs/reference/engine/classes/Instance):
* * *
local function attributeChanged(attributeName)
print(attributeName, "changed")
end
instance.AttributeChanged:Connect(attributeChanged)
See also:
* [Instance:SetAttribute()](/docs/reference/engine/classes/Instance#SetAttribute), sets the attribute with the given name to the given value
* [Instance:GetAttribute()](/docs/reference/engine/classes/Instance#GetAttribute), returns the attribute which has been assigned to the given name
* [Instance:GetAttributes()](/docs/reference/engine/classes/Instance#GetAttributes), returns a dictionary of string → variant pairs for each of the instance's attributes
* [Instance:GetAttributeChangedSignal()](/docs/reference/engine/classes/Instance#GetAttributeChangedSignal), returns an event that fires when the given attribute changes
#### Parameters
attribute: [string](/docs/luau/strings)
The name of the attribute that has been changed.
### Changed
The Changed event fires right after most properties change on objects. It is possible to find the present value of a changed property by using object\[property\]. To get the value of a property before it changes, you must have stored the value of the property before it changed.
If you are only interested in listening to the change of a specific property, consider using the GetPropertyChangedSignal method instead to get an event that only fires when a given property changes.
This event does not fire for physics-related changes, like when the [CFrame](/docs/reference/engine/datatypes/CFrame), Velocity, RotVelocity, Position, Orientation and [CFrame](/docs/reference/engine/datatypes/CFrame) properties of a [BasePart](/docs/reference/engine/classes/BasePart) change due to gravity. To detect changes in these properties, consider using a physics-based event like [RunService.Stepped](/docs/reference/engine/classes/RunService#Stepped) or [BasePart.Touched](/docs/reference/engine/classes/BasePart#Touched). A while-true-do loop can also work.
For "-Value" objects, this event behaves differently: it only fires when the Value property changes. See individual pages for [IntValue](/docs/reference/engine/classes/IntValue), [StringValue](/docs/reference/engine/classes/StringValue), etc for more information. To detect other changes in these objects, you must use GetPropertyChangedSignal instead.
#### Parameters
property: [string](/docs/luau/strings)
The name of the property that changed.
#### Code Samples
This sample demonstrates the subtleties of the Changed event on normal objects and "-Value" objects.
Changed Event
* * *
-- Demonstrate the Changed event by creating a Part
local part = Instance.new("Part")
part.Changed:Connect(print)
-- This fires Changed with "Transparency"
part.Transparency = 0.5
-- Similarly, this fires Changed with "Number"
part.Name = "SomePart"
-- Since changing BrickColor will also change other
-- properties at the same time, this line fires Changed
-- with "BrickColor", "Color3" and "Color3uint16".
part.BrickColor = BrickColor.Red()
-- A NumberValue holds a double-precision floating-point number
local vNumber = Instance.new("NumberValue")
vNumber.Changed:Connect(print)
-- This fires Changed with 123.456 (not "Value")
vNumber.Value = 123.456
-- This does not fire Changed
vNumber.Name = "SomeNumber"
-- A StringValue stores one string
local vString = Instance.new("StringValue")
vString.Changed:Connect(print)
-- This fires Changed with "Hello" (not "Value")
vString.Value = "Hello"
This code sample demonstrates the Changed event firing within a parent object.
Change Detector
* * *
local object = script.Parent
local function onChanged(property)
-- Get the current value of the property
local value = object[property]
-- Print a message saying what changed
print(object:GetFullName() .. "." .. property .. " (" .. typeof(value) .. ") changed to " .. tostring(value))
end
object.Changed:Connect(onChanged)
-- Trigger a simple change in the object (add an underscore to the name)
object.Name = "_" .. object.Name
### ChildAdded
Fires after an object is parented to this [Instance](/docs/reference/engine/classes/Instance).
Note, when using this function on a client to detect objects created by the server it is necessary to use [Instance:WaitForChild()](/docs/reference/engine/classes/Instance#WaitForChild) when indexing these object's descendants. This is because the object and its descendants are not guaranteed to replicate from the server to the client simultaneously. For example:
* * *
workspace.ChildAdded:Connect(function(child)
-- need to use WaitForChild as descendants may not have replicated yet
local head = child:WaitForChild("Head")
end)
Note, this function only works for immediate children of the [Instance](/docs/reference/engine/classes/Instance). For a function that captures all descendants, use [Instance.DescendantAdded](/docs/reference/engine/classes/Instance#DescendantAdded).
See also, [Instance.ChildRemoved](/docs/reference/engine/classes/Instance#ChildRemoved).
#### Parameters
child: [Instance](/docs/reference/engine/classes/Instance)
The [Instance](/docs/reference/engine/classes/Instance) that has been added.
#### Code Samples
This snippet prints the names of objects as they are added to the Workspace:
Instance.ChildAdded
* * *
local function onChildAdded(instance)
print(instance.Name .. " added to the workspace")
end
workspace.ChildAdded:Connect(onChildAdded)
local part = Instance.new("Part")
part.Parent = workspace --> Part added to the Workspace
### ChildRemoved
Fires after a child is removed from this [Instance](/docs/reference/engine/classes/Instance).
Removed refers to when an object's parent is changed from this [Instance](/docs/reference/engine/classes/Instance) to something other than this [Instance](/docs/reference/engine/classes/Instance). Note, this event will also fire when a child is destroyed (using [Instance:Destroy()](/docs/reference/engine/classes/Instance#Destroy)) as the destroy function sets an object's parent to nil.
This function only works for immediate children of the [Instance](/docs/reference/engine/classes/Instance). For a function that captures all descendants, use [Instance.DescendantRemoving](/docs/reference/engine/classes/Instance#DescendantRemoving).
See also [Instance.ChildAdded](/docs/reference/engine/classes/Instance#ChildAdded).
#### Parameters
child: [Instance](/docs/reference/engine/classes/Instance)
The [Instance](/docs/reference/engine/classes/Instance) that has been removed.
#### Code Samples
This snippet prints the names of objects as they are removed from the Workspace:
Instance.ChildRemoved
* * *
local function onChildRemoved(instance)
print(instance.Name .. " removed from the workspace")
end
workspace.ChildRemoved:Connect(onChildRemoved)
local part = Instance.new("Part")
part.Parent = workspace
task.wait(2)
part:Destroy()
### DescendantAdded
The DescendantAdded event fires after a descendant is added to the [Instance](/docs/reference/engine/classes/Instance).
As DescendantAdded fires for every descendant, parenting an object to the [Instance](/docs/reference/engine/classes/Instance) will fire the event for this object and all of its descendants individually.
Developers only concerned with the immediate children of the [Instance](/docs/reference/engine/classes/Instance) should use [Instance.ChildAdded](/docs/reference/engine/classes/Instance#ChildAdded) instead.
See also [Instance.DescendantRemoving](/docs/reference/engine/classes/Instance#DescendantRemoving).
#### Parameters
descendant: [Instance](/docs/reference/engine/classes/Instance)
The [Instance](/docs/reference/engine/classes/Instance) that has been added.
#### Code Samples
This following example will print the name of any object that is added to the Workspace:
Instance.DescendantAdded
* * *
local function onDescendantAdded(descendant)
print(descendant)
end
workspace.DescendantAdded:Connect(onDescendantAdded)
local part = Instance.new("Part")
part.Parent = workspace
### DescendantRemoving
DescendantRemoving fires immediately before the [Parent](/docs/reference/engine/classes/Instance#Parent) of a descendant of the [Instance](/docs/reference/engine/classes/Instance) changes such that the object is no longer a descendant of the Instance. [Destroy](/docs/reference/engine/classes/Instance#Destroy) and [Remove](/docs/reference/engine/classes/Instance#Remove) change an object's Parent to nil, so calling these on a descendant of an object will therefore cause this event to fire.
Since this event fires before the descendant's removal, the Parent of the descendant will be unchanged, i.e., it will still be a descendant at the time of this event firing. If the descendant is also a child of the object, It will also fire before ChildRemoved. There is no similar event called "DescendantRemoved".
If a descendant has children, this event fires with the descendant first followed by its descendants.
#### Example
The example below should help clarify how DescendantRemoving fires when there are several objects involved.

* Calling [Remove](/docs/reference/engine/classes/Instance#Remove) on PartA would cause DescendantRemoving to fire on both ModelA and Model, in that order.
* Setting the [Parent](/docs/reference/engine/classes/Instance#Parent) of PartA to ModelB would cause DescendantRemoving to fire on ModelA but not Model (as Model would still be an ancestor of PartA).
* Calling [Destroy](/docs/reference/engine/classes/Instance#Destroy) on ModelA would cause DescendantRemoving to fire multiple times on several objects:
1. On Model with ModelA, PartA then FireA.
2. On ModelA, with PartA then FireA.
3. On PartA with FireA.
#### Warning
This event fires with the descendant object that is being removed. Attempting to set the [Parent](/docs/reference/engine/classes/Instance#Parent) of the descendant being removed to something else will fail with the following warning: "Something unexpectedly tried to set the parent of X to Y while trying to set the parent of X. Current parent is Z", where X is the removing descendant, Y is the ignored parent setting, and Z is the original parent of X. Below is an example that demonstrates this:
* * *
workspace.DescendantRemoving:Connect(function(descendant)
-- Don't manipulate the parent of descendant in this function!
-- This event fires BECAUSE the parent of descendant was manipulated,
-- and the change hasn't happened yet, i.e. this function fires before that happens.
-- Therefore, it is problematic to change the parent like this:
descendant.Parent = game
end)
local part = Instance.new("Part")
part.Parent = workspace
part.Parent = nil -- This triggers DescendantRemoving on Workspace:
--> Something unexpectedly tried to set the parent of Part to NULL while trying to set the parent of Part. Current parent is Workspace.
See also [DescendantAdded](/docs/reference/engine/classes/Instance#DescendantAdded).
#### Parameters
descendant: [Instance](/docs/reference/engine/classes/Instance)
The [Instance](/docs/reference/engine/classes/Instance) that is being removed.
#### Code Samples
The following example prints the name of any descendant as it is being removed from the Workspace:
Instance.DescendantRemoving
* * *
workspace.DescendantRemoving:Connect(function(descendant)
print(descendant.Name .. " is currently parented to " .. tostring(descendant.Parent))
end)
local part = Instance.new("Part")
part.Parent = workspace
part.Parent = nil
--> Part is currently parented to Workspace
print(part.Parent)
--> nil
### Destroying
The Destroying event fires immediately before the Instance or one of its ancestors is destroyed with Instance.Destroy().
The Instance will never be deleted from memory while a connected function is still using it. However, if the function yields at any point, the Instance and its descendants will be parented to nil.
When deleting an instance in Studio, such as manually deleting through the Explorer or through a plugin, the instance isn't destroyed. Instead, the parent is set to nil which you can track with [Instance.AncestryChanged](/docs/reference/engine/classes/Instance#AncestryChanged).
#### Code Samples
This sample demonstrates how an Instance being destroyed remains in place until the connected function yields.
Using the Destroying Event
* * *
local part = Instance.new("Part", workspace)
local function onPartDestroying()
print("Before yielding:", part:GetFullName(), #part:GetChildren())
task.wait()
print("After yielding:", part:GetFullName(), #part:GetChildren())
end
part.Destroying:Connect(onPartDestroying)
part:Destroy()
### childAdded
DEPRECATED
DEPRECATED
This deprecated event is a variant of [Instance.ChildAdded](/docs/reference/engine/classes/Instance#ChildAdded) which should be used instead.
#### Parameters
child: [Instance](/docs/reference/engine/classes/Instance) |