Instance

사용되지 않는 항목 표시

*이 콘텐츠는 AI(베타)를 사용해 번역되었으며, 오류가 있을 수 있습니다. 이 페이지를 영어로 보려면 여기를 클릭하세요.

만들 수 없음
찾아볼 수 없음

는 Roblox 클래스 계층에서 트리의 일부가 될 수 있는 모든 클래스의 기본 클래스입니다.

루트 Instance 개체를 직접 만들 수는 없지만 특수한 Instance.new() 생성자는 클래스 이름을 매개 변수로 사용하여 코드를 통해 개체를 만들고 생성된 개체를 반환합니다.

요약

속성

  • 병렬 읽기

    Instance 및 그 후손이 Instance:Clone()를 사용하여 복제할 수 있고 저장되거나 게시될 수 있는지 여부를 결정합니다.

  • Capabilities:SecurityCapabilities
    병렬 읽기

    이 컨테이너 내의 스크립트에 사용할 수 있는 기능 집합.

  • 병렬 읽기

    Instance의 고유하지 않은 식별자입니다.

  • 복제되지 않음
    병렬 읽기

    Instance의 계층 부모를 결정합니다.

  • 숨김
    플러그인 보안
    병렬 읽기
    사용되지 않음

    CoreGui 개체를 보호하는 데 사용되었던 사용되지 않는 속성.

  • 복제되지 않음
    병렬 읽기

    인스턴스를 샌드박스 컨테이너로 전환합니다.

  • UniqueId:UniqueId
    복제되지 않음
    스크립팅할 수 없음
    Roblox 보안
    병렬 읽기

    인스턴스의 고유 식별자.

메서드

이벤트

속성

Archivable

병렬 읽기

이 속성은 경험이 게시되거나 저장될 때, 또는 Clone() 가 인스턴스의 조상 중 하나에서 호출될 때 인스턴스가 포함되어야 하는지 여부를 결정합니다.인스턴스에 직접 호출하면 해당 인스턴스가 아니면 아니면 아니면 아니면 아니면 아니면 아니면 아니면 아니면 아니면 아니면 아니면 아니면 아니면 아니면 아니면 아니면 아니면 아니면 아니면 아니면 아니면 아니면

Duplicate 또는 Copy/Paste 옵션을 사용하여 Studio에서 개체를 복사하면 자체 속성 을 무시하고 복사에 대해 를 설정합니다.


local part = Instance.new("Part")
print(part:Clone()) --> Part
part.Archivable = false
print(part:Clone()) --> nil

Capabilities

SecurityCapabilities
병렬 읽기

이 인스턴스 내의 스크립트에 사용할 수 있는 기능 집합.기능이 적용되려면 Instance.Sandboxed 속성을 활성화해야 합니다.

이 속성은 실험적 기능에 사용됩니다. 자세한 내용은 스크립트 기능을 참조하십시오.

Name

병렬 읽기

Instance의 고유하지 않은 식별자입니다.이름은 개체 계층을 구성하고 스크립트가 특정 개체에 액세스할 수 있도록 하면서 사용됩니다.인스턴스의 이름은 크기가 100자를 초과할 수 없습니다.

개체의 이름은 다음 방법을 사용하여 데이터 모델 계층을 통해 개체에 액세스하는 데 자주 사용됩니다: The name of an object is often used to access the object through the data model hierarchy using the following methods:


local Workspace = game:GetService("Workspace")
local baseplate = Workspace.Baseplate
local baseplate = Workspace["Baseplate"]
local baseplate = Workspace:FindFirstChild("BasePlate")

점 연산자(.)를 사용하여 개체에 액세스하려면 이름이 밑줄 또는 문자로 시작해야 하며, 나머지 이름은 문자, 숫자 또는 밑줄(다른 특수 문자는 없음)만 포함할 수 있습니다.개체의 이름이 이 구문을 따르지 않으면 도트 연산자를 사용하여 액세스할 수 없으며 Luau는 이름을 식별자로 해석하지 않습니다.

동일한 이름을 가진 여러 개체가 형제인 경우, 해당 이름으로 개체를 인덱싱하려는 모든 시도는 Instance:FindFirstChild()와 유사하게 하나의 개체만 반환하지만, 항상 원하는 개체는 아닙니다.특정 개체에 코드를 통해 액세스해야 하는 경우 고유한 이름을 부여하거나 형제 중 누구도 동일한 이름을 공유하지 않도록 보장하는 것이 좋습니다.

또한 참조하십시오 Instance:GetFullName() 개체의 계층을 포함하여 전체 이름을 얻으려면.

Parent

복제되지 않음
병렬 읽기

Parent 속성은 Instance의 계층 부모를 결정합니다.다음 용어는 이 속성이 설정되는 방법에 대해 이야기할 때 일반적으로 사용됩니다:

  • 개체는 자식 개체이거나, 자식 개체로 설정되거나, 또는 그 자식 개체가 해당 개체로 설정되면 다른 개체입니다.An object is a child of, or is parented to , another object when its Parent is set to that object.

  • 후손 은 그 개체의 자식, 그리고 자식의 후손도 포함합니다.

  • 인스턴스가 하위인 모든 개체는 조상 입니다.The Instance of an instance are all the objects that the instance is a descendant of.

그것은 Parent 속성에서 많은 다른 API 멤버가 이름을 얻는데, 예를 들어 GetChildren()FindFirstChild()과 같습니다.이 속성은 경험에 개체가 존재하는지 또는 제거해야 하는지도 관리하는 데 사용됩니다.개체의 부모가 DataModel 에 있으면 변수에 저장되거나 다른 개체의 속성에 참조되는 한, 개체가 경험에 남아 있습니다; 그렇지 않으면 개체가 자동으로 제거됩니다.

호출하면 에서 모든 하위 요소의 및 모든 하위 요소의 가 로 설정되고 또한 잠금됩니다.파괴된 개체의 Parent를 설정할 때 오류가 발생합니다.

새로 생성된 개체는 Instance.new()를 사용하여 만들어지며, 일반적으로 한 개가 설정될 때까지 부모가 없고 표시되지 않거나 기능을 수행하지 않습니다.

개체 복제

서버에서 생성된 개체는 복제되는 개체에 부모가 되기 전까지 클라이언트에 복제되지 않습니다.개체를 생성하고 많은 속성을 설정할 때 Parent 속성 last 를 설정하는 것이 좋습니다.이렇게 하면 여러 속성 변경을 복제하는 대신 개체가 한 번만 복제됩니다.


local Workspace = game:GetService("Workspace")
-- 새 인스턴스의 부모 마지막으로 설정(권장)
local part = Instance.new("Part")
part.Position = Vector3.new(0, 10, 0)
part.Parent = Workspace

그러나 부모가 아직 설정되지 않은 Model의 부모에 부품을 부모로 설정하면 모델이 복제되지 않을 것이므로 각 부품을 해당 모델로 부모로 설정하는 것이 허용됩니다.

RobloxLocked

숨김
플러그인 보안
병렬 읽기

이 속성은 CoreGui 서비스의 개체를 무단으로 변경되지 않도록 보호하기 위해 사용되었습니다.사용되지 않으며 아무것도 하지 않습니다.

Sandboxed

복제되지 않음
병렬 읽기

인스턴스를 샌드박스된 컨테이너로 변환하여 특정 컨테이너 내의 스크립트가 수행할 수 있는 작업을 제한합니다.Turns the instance to be a sandboxed container , an experimental feature which limits the actions that scripts inside a particular container can perform.자세한 내용은 스크립트 기능을 참조하십시오.

UniqueId

UniqueId
복제되지 않음
스크립팅할 수 없음
Roblox 보안
병렬 읽기

고유한 식별자는 고유하지 않을 수도 있는 Instance.Name와는 구별되는 인스턴스의 고유한 식별자입니다.

메서드

AddTag

()

이 메서드는 태그를 인스턴스에 적용하며, 태그가 이미 적용된 경우 효과가 없습니다.태그를 성공적으로 추가하면 지정된 태그로 생성된 신호가 CollectionService:GetInstanceAddedSignal()에 발사됩니다.

경고
  • 클라이언트 측에서 추가된 인스턴스의 태그는 서버가 나중에 해당 인스턴스에 태그를 추가하거나 제거하면 삭제됩니다, 서버는 모든 태그를 복제하고 이전 태그를 덮어쓰기 때문입니다.

  • 인스턴스를 태그할 때 일부 리소스가 태그의 기능을 제공하기 위해 사용되는 것이 일반적입니다(예: 이벤트 연결 또는 테이블).메모리 누수를 방지하려면 태그가 더 이상 필요하지 않을 때 이를 정리하는 것이 좋습니다(연결 해제, nil).Instance:RemoveTag() , Instance:Destroy() 을 호출하거나 CollectionService:GetInstanceRemovedSignal() 에서 반환된 신호에 연결된 함수에서 이를 수행합니다.

매개 변수

tag: string
기본값: ""

반환

()

ClearAllChildren

()

이 함수는 인스턴스의 모든 자식과 후손을 파괴합니다.

모든 자식과 후손을 파괴하고 싶지 않은 경우 모든 자식과 후손을 루프하여 선택하려면 Instance:GetChildren() 또는 Instance:GetDescendants()을 사용하여 선택하십시오.예를 들어, 다음 코드 샘플은 다음과 같이 에서 내려오는 모든 것을 파괴합니다:


local Workspace = game:GetService("Workspace")
local model = Workspace:FindFirstChild("TestModel")
for _, descendant in model:GetDescendants() do
if descendant:IsA("BasePart") then
descendant:Destroy()
end
end

반환

()

코드 샘플

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() 는 인스턴스와 모든 하위 인스턴스의 복사본을 만들고, Archivable 가 아닌 모든 인스턴스를 무시합니다.루트 인스턴스의 복사본은 이 메서드에 의해 반환되고, Parentnil로 설정됩니다.인스턴스 자체에 가 설정되어 있으면 이 함수가 로 반환됩니다.

참조 속성인 ObjectValue.Value가 복제된 인스턴스에 설정되면 복사본의 속성 값은 원래의 값에 따라 달라집니다.

  • 참조 속성이 복제된 인스턴스를 참조하면 복사가 복제에 참조됩니다.
  • 참조 속성이 복제되지 않은 개체를 참조하는 경우 동일한 값이 복사본에 유지됩니다.

반환

코드 샘플

Demonstrates cloning a model using Instance:Clone().

Cloning an Instance

local Workspace = game:GetService("Workspace")
-- Get a reference to an existing object
local model = script.Parent.Model
-- Create a clone of the model
local clone = model:Clone()
-- Move the clone so it's not overlapping the original model
clone:PivotTo(model.PrimaryPart.CFrame - (Vector3.xAxis * 10))
-- Add the clone to the Workspace
clone.Parent = Workspace

Destroy

()

Instance.Parent 속성을 nil , Instance.Parent 속성을 잠그고, 모든 연결을 차단하고, 모든 자식에게 Destroy() 을 호출합니다.이 함수는 더 이상 필요하지 않은 개체를 처리하는 올바른 방법입니다.

불필요한 개체를 처분하는 것이 중요합니다, 왜냐하면 장소의 불필요한 개체와 연결은 시간이 지남에 따라 심각한 성능 문제로 이어질 수 있는 메모리를 사용하기 때문입니다.

개체에 대해 Destroy() 를 호출한 후 최선의 방법으로, 개체(또는 그 하위)를 참조하는 모든 변수를 nil 로 설정합니다.이렇게 하면 코드가 개체와 관련된 작업에 액세스하지 못합니다.


local part = Instance.new("Part")
part.Name = "Hello, world"
part:Destroy()
-- 다음을 수행하지 마십시오:
print(part.Name) --> "안녕하세요, 세상"
-- 위의 줄이 작동하지 않도록 수행하십시오:
part = nil

이 메서드에 의해 Instance가 파괴되면 Instance.Parent 속성이 잠겨져 재사용할 수 없습니다.To 일시적으로 개체를 파괴하지 않고 대신 제거하려면 Parentnil 로 설정합니다.예를 들어:


local Workspace = game:GetService("Workspace")
object.Parent = nil
task.wait(2)
object.Parent = Workspace

일정 시간 후에 개체를 파괴하려면 Debris:AddItem()를 사용하십시오.


반환

()

코드 샘플

Demonstrates destroying a Part using the Instance:Destroy() function.

This function is the correct way to dispose of objects that are no longer required.

Instance:Destroy()

local part = script.Parent.Part
part:Destroy()

FindFirstAncestor

병렬 쓰기

주어진 이름과 동일한 Instance의 첫 번째 조상을 반환합니다.Returns the first ancestor of the whose Instance.Name is equal to the given name.

이 함수는 위쪽으로 작동하므로 인스턴스의 즉각적인 Instance.Parent 에서 시작하고 DataModel 쪽으로 작동합니다.일치하는 조상이 없으면 nil 을 반환합니다.

다음 코드 스니펫은 Car라는 개체의 첫 번째 조상을 찾을 것입니다.


local car = object:FindFirstAncestor("Car")

특정 클래스의 조상을 찾는 이 함수의 변형은 Instance:FindFirstAncestorOfClass()Instance:FindFirstAncestorWhichIsA()를 참조하십시오.

매개 변수

name: string

찾을 Instance.Name 대상.

기본값: ""

반환

FindFirstAncestorOfClass

병렬 쓰기

반환 주어진 클래스와 동일한 Instance 의 첫 번째 조상을 반환합니다.Returns the first ancestor of the whose Object.ClassName is equal to the givenclassName.

이 함수는 위쪽으로 작동하므로 인스턴스의 즉각적인 Instance.Parent 에서 시작하고 DataModel 쪽으로 작동합니다.일치하는 조상이 없으면 nil 을 반환합니다.

이 함수의 일반적인 사용은 속해 있는 을 찾는 것입니다. 예를 들어:


local model = part:FindFirstAncestorOfClass("Model")

이 함수는 Instance:FindFirstAncestor()에서 확인하는 대신 Object.ClassName 속성을 확인하는 Instance.Name의 변형입니다.Instance:FindFirstAncestorWhichIsA() 또한 존재하며, 클래스 상속을 존중하기 위해 대신 Object:IsA() 방법을 사용합니다.

매개 변수

className: string

찾을 Object.ClassName 대상.

기본값: ""

반환

FindFirstAncestorWhichIsA

병렬 쓰기

반환 대상 클래스에 대해 Object:IsA() 가 참으로 반환하는 첫 번째 조상 Instance 을 반환합니다.Returns the first ancestor of the for whom returns true for the givenclassName.

이 함수는 위쪽으로 작동하므로 인스턴스의 즉각적인 Instance.Parent 에서 시작하고 DataModel 쪽으로 작동합니다.일치하는 조상이 없으면 nil 을 반환합니다.

Instance:FindFirstAncestorOfClass() 와 달리, 이 함수는 클래스 상속을 존중하는 Object:IsA() 를 사용합니다. 예를 들어:


print(part:IsA("Part")) --> true
print(part:IsA("BasePart")) --> true
print(part:IsA("Instance")) --> true

따라서 다음 코드 샘플은 또는 또는 여부에 관계없이 첫 번째 조상을 반환합니다.


local part = object:FindFirstAncestorWhichIsA("BasePart")

또한 참조하십시오 Instance:FindFirstAncestor() .

매개 변수

className: string

찾을 Object.ClassName 대상.

기본값: ""

반환

FindFirstChild

병렬 쓰기

지정된 이름으로 Instance 의 첫 번째 자식을 반환하거나 nil 없는 경우 해당 자식이 없습니다.선택적 recursive 인수가 true 이면 이 함수는 Instance 의 직접 자식이 아닌 모든 하위 요소를 검색합니다.

개체의 존재 확인

FindFirstChild() 는 계속하기 전에 개체가 존재하는지 확인해야 하는 경우 필요합니다.점 연산자를 사용하여 이름으로 자식을 인덱싱하려고 하면 자식이 존재하지 않으면 오류가 발생합니다.


local Workspace = game:GetService("Workspace")
-- 부품이 작업 영역에 없으면 다음 줄 오류가 발생합니다
Workspace.Part.Transparency = 0.5

FindFirstChild()를 사용하여 먼저 Part을 확인한 다음 if 문을 사용하여 필요한 코드를 실행합니다.


local Workspace = game:GetService("Workspace")
local part = Workspace:FindFirstChild("Part")
if part then
part.Transparency = 0.5
end
이름이 속성과 일치하는 자식 찾기

때로는 개체의 Name 가 해당 속성의 Parent 와 동일합니다.점 연산자를 사용할 때 속성은 이름을 공유하는 경우 자식보다 우선합니다.

다음 예제에서는 Folder이라는 요소가 Part에 추가되었으며, 이 요소에는 Part.Color도 있습니다.Part.Color는 폴더가 아닌 Color3를 참조합니다.


local part = Instance.new("Part")
local folder = Instance.new("Folder")
folder.Name = "Color"
folder.Parent = part
local c = part.Color --> 색상 3
local c2 = part:FindFirstChild("Color") --> The Folder

이 방식으로 FindFirstChild()를 사용하는 이점은 새로운 속성의 도입으로 코드에 위험이 발생하지 않는다는 것입니다.

성능 노트

FindFirstChild() 점 연산자를 사용하는 것보다 약 20% 더 오래 걸리고 단순히 개체에 대한 참조를 저장하는 것보다 거의 8배 더 오래 걸립니다.따라서 좁은 루프나 함수에 연결된 RunService.HeartbeatRunService.PreRender와 같은 성능에 의존하는 코드에서 호출하지 않아야 합니다.대신 변수에 결과를 저장하거나, 특정 이름의 자식이 사용 가능해지면 검색하기 위해 ChildAdded 또는 WaitForChild() 를 사용하는 것을 고려하십시오.

매개 변수

name: string

검색할 Instance.Name 대상.

기본값: ""
recursive: boolean

검색이 재귀적으로 수행되어야 하는지 여부.

기본값: false

반환

코드 샘플

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

병렬 쓰기

반환하는 첫 번째 자식은 InstanceClassName 가 지정된 className 와 동일한 아이입니다.Instance:FindFirstChildWhichIsA() 와 달리, 이 함수는 클래스 상속을 무시하고 className 에 부합하는 개체만 반환합니다.일치하는 자식이 없으면 이 함수는 nil 을 반환합니다.

매개 변수

className: string

찾을 Object.ClassName 대상.

기본값: ""

반환

코드 샘플

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에 대해 반환되며, Object:IsA()에서 지정된 클래스에 대해 true를 반환합니다.

일치하는 자식이 없으면 이 함수는 nil를 반환합니다.선택적 재귀 인수가 참이면, 이 함수는 Instance의 직접 자식이 아닌 모든 하위 요소를 검색합니다.

Instance:FindFirstChildOfClass() 와 달리, 이 함수는 클래스 상속을 존중하는 Object:IsA() 를 사용합니다. 예를 들어:


print(part:IsA("Part")) --> 참
print(part:IsA("BasePart")) --> 참
print(part:IsA("Instance")) --> true

따라서 다음 코드 샘플은 첫 번째 BasePart 자식을 반환하며, 이가 WedgePart 또는 MeshPart 또는 Part인지 여부에 관계없습니다.


local part = object:FindFirstChildWhichIsA("BasePart")

이름으로 자식을 찾는 개발자는 대신 Instance:FindFirstChild()를 사용해야 합니다.

매개 변수

className: string

검색할 Object.ClassName 대상.

기본값: ""
recursive: boolean

검색이 재귀적으로 수행되어야 하는지 여부.

기본값: false

반환

FindFirstDescendant

병렬 쓰기

지정된 Instance.Name 로 찾은 첫 번째 하위 요소를 반환합니다.

이 메서드는 비활성화되어 사용할 수 없습니다.인스턴스의 첫 번째 후손을 찾으려면 recursive 매개 변수를 Instance:FindFirstChild() 대신 사용하는 것을 고려하십시오.

매개 변수

name: string

검색할 Instance.Name 대상.

기본값: ""

반환

GetActor

병렬 쓰기

InstanceActor 인 경우, Actor 자체가 반환됩니다.그렇지 않으면 가장 가까운 조상 Actor 이 반환됩니다.조상이 없으면 Actor , 결과는 nil 입니다.


반환

찾은 Actor .

GetAttribute

Variant
병렬 쓰기

이 메서드는 지정된 특성 이름에 할당된 값을 반환합니다. 특성이 할당되지 않았다면 nil가 반환됩니다.

예를 들어 다음 코드 스니펫은 설정하고 인스턴스의 InitialPosition 특성 값을 가져옵니다:


local Workspace = game:GetService("Workspace")
local part = Workspace.Part
part:SetAttribute("InitialPosition", part.Position)
local initialPosition = instance:GetAttribute("InitialPosition")
print(initialPosition)
또한 참조하세요

매개 변수

attribute: string

검색되는 특성의 이름.

기본값: ""

반환

Variant

지정된 특성 이름에 할당된 값. 특성이 할당되지 않은 경우 nil가 반환됩니다.

GetAttributeChangedSignal

이 함수는 특정 지정된 특성이 변경될 때만 발생하는 이벤트를 반환하며, 효과적으로 이벤트와 비슷하지만 특성에 대해서는 그렇지 않습니다.

일반적으로 특성 이름을 확인하는 함수로 연결하는 대신 이 메서드를 사용하는 것이 좋습니다. Changed 와 함께 특성 이름을 확인하는 함수를 사용하는 것이 좋습니다.동일한 특성 이름을 가진 동일한 개체에서 이 메서드에 대한 후속 호출은 동일한 이벤트를 반환합니다.

다음 코드 예제는 부품의 InitialPosition 특성이 변경될 때 함수 attributeChanged()를 발동하는 신호를 반환합니다:


local Workspace = game:GetService("Workspace")
local part = Workspace.Part
part:SetAttribute("InitialPosition", part.Position)
local function attributeChanged()
print("Attribute changed")
end
part:GetAttributeChangedSignal("InitialPosition"):Connect(attributeChanged)

또한 인스턴스에서 어떤 특성이 변경될 때마다 발생하는 Instance.AttributeChanged도 참조하십시오.

매개 변수

attribute: string

변경 신호가 반환되는 지정된 특성의 이름.

기본값: ""

반환

지정된 특성이 변경될 때 발생하는 이벤트.

GetAttributes

병렬 쓰기

이 메서드는 키가 특성 이름이고 값이 비nil인 각 특성에 대한 키-값 사전을 반환합니다.

예를 들어 다음 코드 스니펫은 인스턴스의 특성과 값을 출력합니다:


local Workspace = game:GetService("Workspace")
local part = Workspace.Part
part:SetAttribute("InitialPosition", part.Position)
part:SetAttribute("CanUse", true)
for name, value in part:GetAttributes() do
print(name .. " = " .. value)
end

또한 참조하십시오 Instance:GetAttribute() 지정된 특성 이름에 할당된 값을 반환하는 것.


반환

문자열이 특성 이름이고 변형이 비공백 값인 각 특성에 대한 문자열 → 변형 쌍 사전입니다. 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

Instances
병렬 쓰기

모든 인스턴스의 직접 자식이나 개체와 동일한 모든 모든 요소를 포함하는 배열(숫자로 인덱스된 테이블)을 반환합니다.숫자 또는 일반 반복기를 사용하여 배열을 반복할 수 있습니다.The array can be iterated upon using either a numeric or generic for-loop:


local Workspace = game:GetService("Workspace")
-- 숫자 포함 루프 예시
local children = Workspace:GetChildren()
for i = 1, #children do
local child = children[i]
print(child.Name .. " is child number " .. i)
end

local Workspace = game:GetService("Workspace")
-- 일반 for 루프 예제
local children = Workspace:GetChildren()
for i, child in children do
print(child.Name .. " is child number " .. i)
end

자식은 속성 Parent가 개체에 설정된 순서에 따라 정렬됩니다.

또한 GetDescendants 함수를 참조하십시오.


반환

Instances

인스턴스의 자식을 포함하는 배열.

코드 샘플

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

찾아볼 수 없음
플러그인 보안

Roblox에서 내부적으로 사용하는 디버그 ID의 코딩된 문자열을 반환합니다. 참고:

  • 이 항목은 보호되어 있습니다. Script 또는 LocalScript 사용하려고 하면 오류가 발생합니다.
  • 디버그 ID는 디버깅 프로세스에서 사용되는 ID입니다.디버거가 애플리케이션이 처리하기 전에 각 명령을 읽을 수 있도록 합니다.Roblox의 모든 개체는 프로세스처럼 작동하며 필요한 경우 디버그할 수 있는 각 실행 지침(또는 '코드')을 실행합니다.
  • 이는 서로 유사한 개체를 구별해야 하는 플러그인(예: 동일한 이름을 공유하는 개체)에 도움이 될 수 있습니다.

매개 변수

scopeLength: number

범위 길이.

기본값: 4

반환

디버그 ID 문자열.

코드 샘플

Instance:GetDebugId

print(workspace:GetDebugId()) --> 39FA_12
print(workspace:GetDebugId(10)) --> 39FA2FEF4D_12
print(workspace:GetDebugId(math.huge)) --> 12

GetDescendants

병렬 쓰기

이 개체 메서드는 해당 개체의 모든 하위 개체를 포함하는 배열을 반환합니다.Instance:GetChildren() 와 달리 이 메서드는 개체의 즉시 자식만 반환하는 것이 아니라 개체의 모든 자식, 그 자식의 모든 자식 등을 찾습니다.


반환

인스턴스의 하위 요소가 포함된 배열.

코드 샘플

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() 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

병렬 쓰기

인스턴스의 조상을 설명하는 문자열을 반환합니다.문자열은 개체와 그 조상의 Name의 결합으로, 마침표로 구분됩니다.The DataModel ( game )는 고려되지 않습니다.예를 들어, Part 에 있는 Workspace 는 반환할 수 있습니다 Workspace.Part .

가 아닌 에서 호출되면 이 함수는 상위 하나를 포함하여 모든 조상을 고려하고 없이 합니다.

이 함수는 로깅과 디버깅에 유용합니다.반환된 문자열을 유용한 작업으로 분석하려고 시도해서는 안됩니다; 이 함수는 개체 이름에서 마침표(또는 다른 기호)를 이스케이프하지 않습니다.즉, 출력이 종종 유효한 Luau 식별자인 것처럼 보이지만 보장되지 않습니다.


반환

Instance의 전체 이름.

코드 샘플

This code sample demonstrates the behavior of 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() 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

GetStyled

Variant

매개 변수

name: string
기본값: ""

반환

Variant

GetStyledPropertyChangedSignal

매개 변수

property: string
기본값: ""

반환

GetTags

병렬 쓰기

이 메서드는 지정된 인스턴스에 적용된 태그 배열을 문자열로 반환합니다.태그는 Studio의 속성 창이나 런타임에 AddTag() 추가할 수 있습니다.

이 메서드는 한 번에 인스턴스에 여러 태그로 작업하려는 경우 유용합니다.그러나 단일 태그의 존재를 확인하기 위해 이 메서드를 사용하는 것은 비효율적입니다; 대신 HasTag()를 사용하여 특정 태그를 확인하십시오.


반환

HasTag

병렬 쓰기

이 메서드는 제공된 태그가 개체에 추가된 경우 true 를 반환합니다.태그는 Studio의 속성 창이나 런타임에 AddTag() 추가할 수 있습니다.

매개 변수

tag: string
기본값: ""

반환

IsAncestorOf

병렬 쓰기

Instance 가 지정된 후손의 조상이면 true를 반환합니다.

Instance 는 개체의 Instance.Parent 또는 부모 중 하나의 Instance.ParentInstance 에 설정되면 개체의 조상으로 간주됩니다.

또한 참조하십시오, Instance:IsDescendantOf() .

매개 변수

descendant: Instance

하위 요소 Instance .

기본값: ""

반환

Instance가 지정된 후손의 조상이면 참입니다.True if the is an ancestor of the given descendant.

코드 샘플

Demonstrates determining if one instance is the ancestor of another using Instance:IsAncestorOf()

Workspace and SpawnLocation are ancestors of the SpawnLocation's decal. Workspace is an ancestor of SpawnLocation.

SpawnLocation and its decal are descendants of Workspace, not ancenstors. Decal is a descendant to SpawnLocation, not an ancestor.

Instance:IsAncestorOf()

local Workspace = game:GetService("Workspace")
local spawnLocation = Workspace.SpawnLocation
local decal = spawnLocation.Decal
-- These statements are true
print(Workspace:IsAncestorOf(spawnLocation))
print(Workspace:IsAncestorOf(decal))
print(spawnLocation:IsAncestorOf(decal))
-- These statements are false
print(spawnLocation:IsAncestorOf(Workspace))
print(decal:IsAncestorOf(Workspace))
print(decal:IsAncestorOf(spawnLocation))

IsDescendantOf

병렬 쓰기

true 가 주어진 조상의 후손인 경우 반환합니다 Instance if an 은 주어진 조상의 후손입니다.

참고로 IsDescendantOf() 는 개체가 제거되었는지 확인하기 위해 nil 매개 변수와 함께 사용할 수 없습니다.

또한 참조하십시오 Instance:IsAncestorOf() .

매개 변수

ancestor: Instance

조상 Instance .

기본값: ""

반환

Instance가 지정된 조상의 후손인 경우 true입니다.

코드 샘플

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

IsPropertyModified

지정된 속성에 저장된 값이 기본값이 아닌 경우 true 를 반환합니다.예를 들어, 출력 속성의 가 를 나타내면 레이블에서 를 호출하면 가 반환되는데, 이는 가 기본값이기 때문입니다.

매개 변수

property: string
기본값: ""

반환

속성이 수정되었는지 여부를 나타내는 부울.

RemoveTag

()

이 메서드는 인스턴스에서 태그를 제거합니다.개체에 태그가 없으면 오류를 발생시키지 않습니다.태그를 성공적으로 제거하면 지정된 태그로 CollectionService:GetInstanceRemovedSignal()에 의해 생성된 신호가 발생합니다.

인스턴스를 태그할 때 일부 리소스가 태그의 기능을 제공하기 위해 사용되는 것이 일반적이며, 예를 들어 이벤트 연결 또는 테이블입니다.메모리 누수를 방지하려면 태그가 더 이상 필요하지 않을 때 이를 정리하는 것이 좋습니다(연결 해제, nil).

매개 변수

tag: string
기본값: ""

반환

()

ResetPropertyToDefault

()

속성을 기본값으로 재설정합니다.예를 들어, 에 대한 호출은 속성의 기본값을 로 설정하는 것과 동일합니다(속성의 기본값).

매개 변수

property: string
기본값: ""

반환

()

SetAttribute

()

이 메서드는 지정된 이름의 특성을 지정된 값으로 설정합니다.제공된 값이 nil 이면 특성이 제거됩니다, 기본적으로 nil 가 반환되기 때문입니다.

예를 들어 다음 코드 스니펫은 인스턴스의 InitialPosition 특성을 Vector3.new(0, 10, 0)로 설정합니다.


local Workspace = game:GetService("Workspace")
local part = Workspace.Part
part:SetAttribute("InitialPosition", Vector3.new(0, 10, 0))
제한

이름 요구 사항 및 제한:

  • 이름은 알파벳 숫자 문자와 밑줄만 사용해야 합니다.
  • 공백이나 고유한 기호는 허용되지 않습니다.
  • 문자열은 100자 이하여야 합니다.
  • 호출자가 Roblox 핵심 스크립트(Roblox에 예약)인 경우를 제외하고 이름은 RBX 로 시작할 수 없습니다.

지원되지 않는 입력특성을 설정하려고 할 때 오류가 발생합니다.

또한 참조하세요

매개 변수

attribute: string

설정 중인 특성의 이름.

기본값: ""
value: Variant

지정된 특성을 설정할 값.

기본값: ""

반환

()

WaitForChild

생성할 수 있음

지정된 이름으로 Instance의 자식을 반환합니다.자식이 존재하지 않으면 현재 스레드를 생성할 때까지 그렇게 됩니다.timeOut 매개 변수가 지정되면 지정된 시간 후에 이 메서드가 시간이 초과되고 nil로 반환됩니다.

주요 사용

WaitForChild() 는 클라이언트에 의해 실행되는 코드를 작업할 때 LocalScript 에서 매우 중요합니다.Roblox 엔진은 서버에서 클라이언트로 개체를 복제하는 시간이나 순서를 보장하지 않습니다.또한 경험에 설정이 true로 설정되어 있으면 플레이어의 캐릭터에서 멀리 떨어진 스트림이 클라이언트에 전송되지 않아 클라이언트에 아직 존재하지 않는 개체를 인덱싱할 때 스크립트가 깨질 수 있습니다.

노트
  • 이 함수는 호출이 수행될 때 지정된 이름의 자식이 존재하지 않으면 반환하지 않습니다.
  • Instance:FindFirstChild() 는 존재할 것으로 예상되는 개체에 대한 WaitForChild() 보다 효율적인 대안입니다.
  • 이 메서드에 대한 호출이 반환되지 않고 5초를 초과하며 어떤 timeOut 매개변수도 지정되지 않은 경우 스레드가 무기한 생성할 수 있는 출력에 경고가 인쇄됩니다.

매개 변수

childName: string

찾을 Instance.Name 대상.

기본값: ""
timeOut: number

선택적 시간 초과 매개 변수.

기본값: ""

반환

코드 샘플

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")

이벤트

AncestryChanged

개체나 그 조상 중 하나의 Instance.Parent 속성이 변경될 때 발생합니다.

이 이벤트에는 두 개의 매개 변수가 포함됩니다: 는 실제로 변경된 의 참조를 포함하며, 는 이 인스턴스의 새로운 에 대한 참조를 포함합니다.

이 이벤트를 사용하여 탐색기나 플러그인을 통한 수동 삭제와 같이 Studio에서 인스턴스 삭제를 추적할 수 있습니다.인스턴스를 Instance:Destroy()로 파괴할 때 검색해야 하는 경우, 대신 Instance.Destroying 이벤트를 사용하십시오.

매개 변수

child: Instance

변경된 InstanceInstance.Parent 가 변경되었습니다.

parent: Instance

새로운 Instance.ParentInstance 가 변경된 새로운 Instance.Parent


코드 샘플

Demonstrates detecting changes to an instance's ancestry by connecting to the Instance.AncestryChanged event.

The ChangingPart's Parent is set to different values overtime. The parent of the part is the part's ancestor, so the Instance.AncestryChanged event will fire whenever it changes.

Instance.AncestryChanged

local Workspace = game:GetService("Workspace")
local redPart = script.Parent.RedPart
local bluePart = script.Parent.BluePart
local changingPart = script.Parent.ChangingPart
-- Change the color of changingPart based on it's Parent
local function onAncestryChanged(part: Part, parent: Instance)
if parent == redPart then
changingPart.Color = Color3.new(1, 0, 0)
elseif parent == bluePart then
changingPart.Color = Color3.new(0, 0, 1)
else
changingPart.Color = Color3.new(1, 1, 1)
end
print(`{part.Name} is now parented to {parent.Name}`)
end
changingPart.AncestryChanged:Connect(onAncestryChanged)
-- Set changingPart's Parent property to different instances over time
while true do
task.wait(2)
changingPart.Parent = redPart
task.wait(2)
changingPart.Parent = bluePart
task.wait(2)
changingPart.Parent = Workspace
end

AttributeChanged

이 이벤트는 특성이 nil 설정되었을 때를 포함하여 인스턴스에서 특성이 변경될 때마다 발생합니다.변경된 특성의 이름이 연결된 함수에 전달됩니다.

예를 들어 다음 코드 스니펫은 부품 특성 중 하나가 변경될 때마다 attributeChanged() 함수를 발동하도록 연결합니다:


local Workspace = game:GetService("Workspace")
local part = Workspace.Part
local function attributeChanged(attributeName)
print(attributeName, "changed")
end
part.AttributeChanged:Connect(attributeChanged)

또한 특정 지정된 특성이 변경될 때 발생하는 이벤트를 반환하는 Instance:GetAttributeChangedSignal()도 참조하십시오.

매개 변수

attribute: string

변경된 특성의 이름.


ChildAdded

개체가 이 Instance 에 부모로 지정된 후 발생합니다.

이 함수를 서버에서 생성된 개체를 감지하기 위해 클라이언트에서 사용할 때, 이러한 개체의 하위를 인덱싱할 때 Instance:WaitForChild()를 사용해야 합니다.이는 개체와 그 하위 개체가 동시에 서버에서 클라이언트로 복제되지 않는다는 보장이 없기 때문입니다.예를 들어:


local Workspace = game:GetService("Workspace")
Workspace.ChildAdded:Connect(function(child)
-- Use WaitForChild() since descendants may not have replicated yet
local head = child:WaitForChild("Head")
end)

참고, 이 함수는 Instance의 즉시 자식에서만 작동합니다. 모든 하위를 캡처하는 함수의 경우 Instance.DescendantAdded를 사용하십시오.

또한 참조하십시오 Instance.ChildRemoved .

매개 변수

child: Instance

추가된 Instance 입니다.


코드 샘플

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

자식이 이 Instance 에서 제거된 후 발생하는 화재.

제거는 개체의 부모가 이 Instance에서 이 Instance로 바뀌었을 때를 가리킵니다.참고, 이 이벤트는 자식이 삭제될 때(Instance:Destroy()를 사용하여) 파괴 함수가 개체의 부모를 nil로 설정하기 때문에 또한 발생합니다.

이 함수는 Instance의 즉시 자식에서만 작동합니다. 모든 하위를 캡처하는 함수의 경우 Instance.DescendantRemoving를 사용하십시오.

또한 참조하십시오 Instance.ChildAdded .

매개 변수

child: Instance

제거된 Instance 입니다.


코드 샘플

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

이 이벤트는 하위 요소가 Instance에 추가된 후 발생합니다.

모든 하위 요소에 대해 발사할 때, 개체를 Instance에 부모로 지정하면 이 개체와 모든 하위 요소의 이벤트가 개별적으로 발생합니다.

걱정되는 것은 직접 자식만 있는 의 경우, 대신 을 사용하십시오.

또한 참조하십시오 Instance.DescendantRemoving .

매개 변수

descendant: Instance

추가된 Instance 입니다.


코드 샘플

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

이 이벤트는 부모의 Instance이 발생하기 직전에 즉시 하위 인스턴스가 더 이상 하위 인스턴스가 아니라는 점에서 부모의 변경 을 발사합니다.Destroy() 인스턴스의 Parentnil 로 변경하여 부모의 하위에서 해당 메서드를 호출하면 이 이벤트가 발생합니다.

이 이벤트는 후손의 제거 전에 발생하므로 , 이 이벤트가 발생할 때 후손의 부모는 변경되지 않습니다.후손이 또한 부모의 직접 자식이면 이 이벤트는 전에 발생합니다.

후손에 자식이 있는 경우, 이 이벤트는 먼저 후손, 그 다음 자식이 있는 순서로 발생합니다.

주의

이 이벤트는 제거되는 하위 개체로 발생합니다.하위 요소의 Parent를 다른 것으로 설정하려는 시도는 실패합니다.아래는 이것을 보여주는 예시입니다:


local Workspace = game:GetService("Workspace")
Workspace.DescendantRemoving:Connect(function(descendant)
-- Do not manipulate the parent of the descendant in this function!
-- This event fires BECAUSE the parent was manipulated, and the change hasn't happened yet
-- Therefore, it is problematic to change the parent like this:
descendant.Parent = game
end)
local part = Instance.new("Part")
part.Parent = Workspace
part.Parent = nil

또한 참조하십시오 DescendantAdded .

매개 변수

descendant: Instance

제거되는 Instance 입니다.


코드 샘플

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

연결된 함수가 여전히 사용하고 있는 동안 메모리에서 Instance 가 삭제되지 않습니다.그러나 함수가 어느 시점에서든 반환되면 Instance 및 그 하위 요소는 nil에 부모가 됩니다.

Workspace.SignalBehavior 속성이 Enum.SignalBehavior.Immediate로 설정되면 이 이벤트는 Instance 또는 그 조상 중 하나가 Instance:Destroy()로 파괴되기 전에 즉시 발생합니다.

Workspace.SignalBehavior 속성이 Enum.SignalBehavior.Deferred로 설정되면 이 이벤트는 다음 재시작 지점에서 발생하며, 이는 Instance 또는 그 조상 중 하나가 Instance:Destroy()로 파괴될 때입니다.

Deferred 동작으로 스크립트를 자체의 Instance.Destroying 이벤트에 연결하는 것은 스크립트가 호출되기 전에 파괴되기 때문에 문제가 있습니다(즉, 실행되지 않음).

Studio에서 수동으로 삭제하거나 플러그인을 통해 삭제하는 등 를 삭제할 때, Explorer를 통해 또는 플러그인을 통해 삭제되지 않습니다.대신, 부모는 nil에 설정되어 추적할 수 있습니다. Instance.AncestryChanged .


코드 샘플

This sample demonstrates how, when using Immediate signal behavior, an Instance being destroyed remains in place until the connected function yields.

Using the Destroying Event (Immediate signals)

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()

This sample demonstrates how, when using Deferred signal behavior, an Instance is destroyed before the signal fires.

Using the Destroying Event (Deferred signals)

local part = Instance.new("Part", workspace)
local function onPartDestroying()
print("In signal:", part:GetFullName(), #part:GetChildren())
end
part.Destroying:Connect(onPartDestroying)
print("Before destroying:", part:GetFullName(), #part:GetChildren())
part:Destroy()
print("After destroying:", part:GetFullName(), #part:GetChildren())

StyledPropertiesChanged