學習
引擎類別
Instance
無法建立
無法瀏覽

*此內容是使用 AI(Beta 測試版)翻譯,可能含有錯誤。若要以英文檢視此頁面,請按一下這裡


概要
繼承成員

API 參考
屬性
Archivable
平行讀取
Instance.Archivable:boolean

archivable
已棄用

Capabilities
平行讀取
功能: CapabilityControl
Instance.Capabilities:SecurityCapabilities

Name
平行讀取
Instance.Name:string

Parent
未複製
平行讀取
Instance.Parent:Instance

PredictionMode
唯讀
未複製
無法建立指令碼
平行讀取
Instance.PredictionMode:Enum.PredictionMode

RobloxLocked
已棄用

Sandboxed
未複製
平行讀取
功能: CapabilityControl
Instance.Sandboxed:boolean

UniqueId
未複製
Roblox 指令碼安全性
Roblox 安全性
平行讀取
Instance.UniqueId:UniqueId

方法
AddTag
Instance:AddTag(tag:string):()
參數
tag:string
返回
()

children
已棄用

ClearAllChildren
Instance:ClearAllChildren():()
返回
()

Clone
功能: CreateInstances
模擬存取權
Instance:Clone():Instance
返回
範例程式碼
複製實例
local Workspace = game:GetService("Workspace")
-- 獲取對現有物件的引用
local model = script.Parent.Model
-- 創建模型的克隆
local clone = model:Clone()
-- 移動克隆,使其不與原始模型重疊
clone:PivotTo(model.PrimaryPart.CFrame - (Vector3.xAxis * 10))
-- 將克隆添加到 Workspace
clone.Parent = Workspace

clone
已棄用

Destroy
Instance:Destroy():()
返回
()
範例程式碼
實例:銷毀()
local part = script.Parent.Part
part:Destroy()

destroy
已棄用

FindFirstAncestor
平行寫入
Instance:FindFirstAncestor(name:string):Instance?
參數
name:string
返回

FindFirstAncestorOfClass
平行寫入
Instance:FindFirstAncestorOfClass(className:string):Instance?
參數
className:string
返回

FindFirstAncestorWhichIsA
平行寫入
Instance:FindFirstAncestorWhichIsA(className:string):Instance?
參數
className:string
返回

FindFirstChild
平行寫入
模擬存取權
Instance:FindFirstChild(
name:string, recursive:boolean
參數
name:string
recursive:boolean
預設值:false
返回
範例程式碼
實例:找第一個子物件
local found = workspace:FindFirstChild("Brick")
if found then
found.Name = "Foo"
end

findFirstChild
已棄用

FindFirstChildOfClass
平行寫入
Instance:FindFirstChildOfClass(className:string):Instance?
參數
className:string
返回
範例程式碼
實例:查找第一个类的子对象
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:FindFirstChildWhichIsA(
className:string, recursive:boolean
參數
className:string
recursive:boolean
預設值:false
返回

FindFirstDescendant
平行寫入
Instance:FindFirstDescendant(name:string):Instance?
參數
name:string
返回

GetActor
平行寫入
Instance:GetActor():Actor?
返回

GetAttribute
平行寫入
模擬存取權
Instance:GetAttribute(attribute:string):Variant
參數
attribute:string
返回
Variant

GetAttributeChangedSignal
Instance:GetAttributeChangedSignal(attribute:string):RBXScriptSignal
參數
attribute:string

GetAttributes
平行寫入
模擬存取權
Instance:GetAttributes():Dictionary

GetChildren
平行寫入
模擬存取權
Instance:GetChildren():Instances
返回
Instances
範例程式碼
實例:獲取子物件
-- 獲取工作區的所有子物件
local children = workspace:GetChildren()
-- 迭代每個子物件
for i = 1, #children do
print(i, children[i].Name) -- 打印子物件名稱
end

getChildren
已棄用

GetDebugId
無法瀏覽
外掛程式安全性
Instance:GetDebugId(scopeLength:number):string
參數
scopeLength:number
預設值:4
返回
範例程式碼
實例:GetDebugId
'print(workspace:GetDebugId()) --> 39FA_12
print(workspace:GetDebugId(10)) --> 39FA2FEF4D_12
print(workspace:GetDebugId(math.huge)) --> 12'

GetDescendants
平行寫入
模擬存取權
Instance:GetDescendants():Instances
返回
Instances
範例程式碼
Instance:GetDescendants
local descendants = workspace:GetDescendants()
-- 遍歷工作區的所有子孫。如果找到
-- BasePart,則將該部件的顏色變為綠色
for _, descendant in pairs(descendants) do
if descendant:IsA("BasePart") then
descendant.BrickColor = BrickColor.Green()
end
end

GetFullName
平行寫入
模擬存取權
Instance:GetFullName():string
返回
範例程式碼
實例:獲取完整名稱
-- 創建一個簡單的階層
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 = "你好,世界"
print(fire:GetFullName()) --> Workspace.Model.你好,世界.Fire
實例:GetFullName Lua 實作
local function getFullName(object)
local result = object.Name
object = object.Parent
while object and object ~= game do
-- 添加父物件名稱
result = object.Name .. "." .. result
-- 向上查詢層級
object = object.Parent
end
return result
end
print(getFullName(workspace.Camera)) --> Workspace.Camera

GetStyled
Instance:GetStyled(
name:string, selector:string?
):Variant
參數
name:string
selector:string?
返回
Variant

GetStyledPropertyChangedSignal
Instance:GetStyledPropertyChangedSignal(property:string):RBXScriptSignal
參數
property:string

GetTags
平行寫入
模擬存取權
Instance:GetTags():{any}
返回

HasTag
平行寫入
模擬存取權
Instance:HasTag(tag:string):boolean
參數
tag:string
返回

IsAncestorOf
平行寫入
模擬存取權
Instance:IsAncestorOf(descendant:Instance):boolean
參數
descendant:Instance
返回
範例程式碼
Instance:IsAncestorOf()
local Workspace = game:GetService("Workspace")
local spawnLocation = Workspace.SpawnLocation
local decal = spawnLocation.Decal
-- 這些敘述為真
print(Workspace:IsAncestorOf(spawnLocation))
print(Workspace:IsAncestorOf(decal))
print(spawnLocation:IsAncestorOf(decal))
-- 這些敘述為假
print(spawnLocation:IsAncestorOf(Workspace))
print(decal:IsAncestorOf(Workspace))
print(decal:IsAncestorOf(spawnLocation))

IsDescendantOf
平行寫入
模擬存取權
Instance:IsDescendantOf(ancestor:Instance):boolean
參數
ancestor:Instance
返回
範例程式碼
實例:IsDescendantOf
local part = Instance.new("Part")
print(part:IsDescendantOf(game))
--> 假
part.Parent = workspace
print(part:IsDescendantOf(game))
--> 真
part.Parent = game
print(part:IsDescendantOf(game))
--> 真

isDescendantOf
已棄用

IsPropertyModified
模擬存取權
Instance:IsPropertyModified(property:string):boolean
參數
property:string
返回

QueryDescendants
模擬存取權
Instance:QueryDescendants(selector:string):Instances
參數
selector:string
返回
Instances

Remove
已棄用

remove
已棄用

RemoveTag
Instance:RemoveTag(tag:string):()
參數
tag:string
返回
()

ResetPropertyToDefault
Instance:ResetPropertyToDefault(property:string):()
參數
property:string
返回
()

SetAttribute
模擬存取權
Instance:SetAttribute(
attribute:string, value:Variant
):()
參數
attribute:string
value:Variant
返回
()

WaitForChild
可暫停
Instance:WaitForChild(
childName:string, timeOut:number
參數
childName:string
timeOut:number
返回
範例程式碼
實例:等待子項
local part = workspace:WaitForChild("Part")
print(part.Name .. " 已被添加到 Workspace")

活動
AncestryChanged
Instance.AncestryChanged(
child:Instance, parent:Instance
參數
child:Instance
parent:Instance
範例程式碼
Instance.AncestryChanged
local Workspace = game:GetService("Workspace")
local redPart = script.Parent.RedPart
local bluePart = script.Parent.BluePart
local changingPart = script.Parent.ChangingPart
-- 根據其 Parent 更改 changingPart 的顏色
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} 現在的父級是 {parent.Name}`)
end
changingPart.AncestryChanged:Connect(onAncestryChanged)
-- 隨著時間的推移將 changingPart 的 Parent 屬性設置為不同的實例
while true do
task.wait(2)
changingPart.Parent = redPart
task.wait(2)
changingPart.Parent = bluePart
task.wait(2)
changingPart.Parent = Workspace
end

AttributeChanged
Instance.AttributeChanged(attribute:string):RBXScriptSignal
參數
attribute:string

ChildAdded
Instance.ChildAdded(child:Instance):RBXScriptSignal
參數
child:Instance
範例程式碼
Instance.ChildAdded
local function onChildAdded(instance)
print(instance.Name .. " 已加入到工作區")
end
workspace.ChildAdded:Connect(onChildAdded)
local part = Instance.new("Part")
part.Parent = workspace --> 物件已加入到工作區

childAdded
已棄用

ChildRemoved
Instance.ChildRemoved(child:Instance):RBXScriptSignal
參數
child:Instance
範例程式碼
實例.子物件移除
local function onChildRemoved(instance)
print(instance.Name .. " 從工作空間移除")
end
workspace.ChildRemoved:Connect(onChildRemoved)
local part = Instance.new("Part")
part.Parent = workspace
task.wait(2)
part:Destroy()

DescendantAdded
Instance.DescendantAdded(descendant:Instance):RBXScriptSignal
參數
descendant:Instance
範例程式碼
實例.後代被添加
local function onDescendantAdded(descendant)
print(descendant)
end
workspace.DescendantAdded:Connect(onDescendantAdded)
local part = Instance.new("Part")
part.Parent = workspace

DescendantRemoving
Instance.DescendantRemoving(descendant:Instance):RBXScriptSignal
參數
descendant:Instance
範例程式碼
實例.後代移除中
workspace.DescendantRemoving:Connect(function(descendant)
print(descendant.Name .. " 目前父屬於 " .. tostring(descendant.Parent))
end)
local part = Instance.new("Part")
part.Parent = workspace
part.Parent = nil
--> 零件目前父屬於 Workspace
print(part.Parent)
--> nil

Destroying
Instance.Destroying():RBXScriptSignal
範例程式碼
使用銷毀事件(即時信號)
local part = Instance.new("Part", workspace)
local function onPartDestroying()
print("暫停之前:", part:GetFullName(), #part:GetChildren())
task.wait()
print("暫停之後:", part:GetFullName(), #part:GetChildren())
end
part.Destroying:Connect(onPartDestroying)
part:Destroy()
使用銷毀事件(延遲信號)
local part = Instance.new("Part", workspace)
local function onPartDestroying()
print("在信號中:", part:GetFullName(), #part:GetChildren())
end
part.Destroying:Connect(onPartDestroying)
print("在銷毀之前:", part:GetFullName(), #part:GetChildren())
part:Destroy()
print("在銷毀之後:", part:GetFullName(), #part:GetChildren())

StyledPropertiesChanged
Instance.StyledPropertiesChanged():RBXScriptSignal

©2026 Roblox Corporation、Roblox、Roblox 標誌及 Powering Imagination 是我們在美國及其他國家地區的部分註冊與未註冊商標。