Classe motore
Instance
*Questo contenuto è tradotto usando AI (Beta) e potrebbe contenere errori. Per visualizzare questa pagina in inglese, clicca qui.
Sommario
Proprietà
UniqueId:UniqueId |
Metodi
Eventi
AncestryChanged(child: Instance,parent: Instance):RBXScriptSignal |
AttributeChanged(attribute: string):RBXScriptSignal |
ChildAdded(child: Instance):RBXScriptSignal |
childAdded(child: Instance):RBXScriptSignal |
ChildRemoved(child: Instance):RBXScriptSignal |
DescendantAdded(descendant: Instance):RBXScriptSignal |
DescendantRemoving(descendant: Instance):RBXScriptSignal |
Membri ereditati
Membri ereditati da Object: 6
Ereditata da
Riferimento API
Proprietà
archivable
RobloxLocked
UniqueId
Instance.UniqueId:UniqueId
Metodi
children
ClearAllChildren
Instance:ClearAllChildren():()
Restituzioni
()
Clone
Restituzioni
Campioni di codice
Clonazione di un'istanza
local Workspace = game:GetService("Workspace")
-- Ottieni un riferimento a un oggetto esistente
local model = script.Parent.Model
-- Crea un clone del modello
local clone = model:Clone()
-- Sposta il clone in modo che non si sovrapponga al modello originale
clone:PivotTo(model.PrimaryPart.CFrame - (Vector3.xAxis * 10))
-- Aggiungi il clone allo Workspace
clone.Parent = Workspaceclone
Destroy
Instance:Destroy():()
Restituzioni
()
Campioni di codice
Istanza:Destroy()
local part = script.Parent.Part
part:Destroy()destroy
FindFirstAncestor
FindFirstAncestorOfClass
FindFirstAncestorWhichIsA
FindFirstChild
findFirstChild
FindFirstChildOfClass
Parametri
Restituzioni
Campioni di codice
Istanza:TrovaPrimoFiglioDiClasse
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
endFindFirstChildWhichIsA
FindFirstDescendant
GetAttribute
GetAttributeChangedSignal
Parametri
Restituzioni
GetChildren
Instance:GetChildren():Instances
Restituzioni
Instances
Campioni di codice
Instance:GetChildren
local children = workspace:GetChildren()
for i = 1, #children do
print(i, children[i].Name)
endgetChildren
GetDebugId
GetDescendants
Instance:GetDescendants():Instances
Restituzioni
Instances
Campioni di codice
Istanza:GetDescendants
local descendants = workspace:GetDescendants()
-- Scorri attraverso tutti i discendenti dello spazio di lavoro. Se viene
-- trovata una BasePart, il codice cambia il colore di quella parte in verde
for _, descendant in pairs(descendants) do
if descendant:IsA("BasePart") then
descendant.BrickColor = BrickColor.Green()
end
endGetFullName
Restituzioni
Campioni di codice
Istanza:GetFullName
-- Crea una gerarchia semplice
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 = "Ciao, mondo"
print(fire:GetFullName()) --> Workspace.Model.Ciao, mondo.FireImplementazione Lua di Instance:GetFullName
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.CameraGetStyled
GetStyledPropertyChangedSignal
Parametri
Restituzioni
IsAncestorOf
Parametri
Restituzioni
Campioni di codice
Instance:IsAncestorOf()
local Workspace = game:GetService("Workspace")
local spawnLocation = Workspace.SpawnLocation
local decal = spawnLocation.Decal
-- Queste affermazioni sono vere
print(Workspace:IsAncestorOf(spawnLocation))
print(Workspace:IsAncestorOf(decal))
print(spawnLocation:IsAncestorOf(decal))
-- Queste affermazioni sono false
print(spawnLocation:IsAncestorOf(Workspace))
print(decal:IsAncestorOf(Workspace))
print(decal:IsAncestorOf(spawnLocation))IsDescendantOf
Parametri
Restituzioni
Campioni di codice
Instance:IsDescendantOf
local part = Instance.new("Part")
print(part:IsDescendantOf(game))
--> falso
part.Parent = workspace
print(part:IsDescendantOf(game))
--> vero
part.Parent = game
print(part:IsDescendantOf(game))
--> veroisDescendantOf
IsPropertyModified
QueryDescendants
Remove
remove
ResetPropertyToDefault
SetAttribute
Eventi
AncestryChanged
Campioni di codice
Instance.AncestryChanged
local Workspace = game:GetService("Workspace")
local redPart = script.Parent.RedPart
local bluePart = script.Parent.BluePart
local changingPart = script.Parent.ChangingPart
-- Cambia il colore di changingPart in base al suo 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} è ora genitore di {parent.Name}`)
end
changingPart.AncestryChanged:Connect(onAncestryChanged)
-- Imposta la proprietà Parent di changingPart su diverse istanze nel tempo
while true do
task.wait(2)
changingPart.Parent = redPart
task.wait(2)
changingPart.Parent = bluePart
task.wait(2)
changingPart.Parent = Workspace
endAttributeChanged
Parametri
ChildAdded
Parametri
Campioni di codice
Instance.ChildAdded
local function onChildAdded(instance)
print(instance.Name .. " aggiunto allo spazio di lavoro")
end
workspace.ChildAdded:Connect(onChildAdded)
local part = Instance.new("Part")
part.Parent = workspace --> Parte aggiunta allo Spazio di lavorochildAdded
ChildRemoved
Parametri
Campioni di codice
Istanza.ChildRemoved
local function onChildRemoved(instance)
print(instance.Name .. " rimosso dal workspace")
end
workspace.ChildRemoved:Connect(onChildRemoved)
local part = Instance.new("Part")
part.Parent = workspace
task.wait(2)
part:Destroy()DescendantAdded
Parametri
Campioni di codice
Instance.DescendantAdded
local function onDescendantAdded(descendant)
print(descendant)
end
workspace.DescendantAdded:Connect(onDescendantAdded)
local part = Instance.new("Part")
part.Parent = workspaceDescendantRemoving
Parametri
Campioni di codice
Instance.DescendantRemoving
workspace.DescendantRemoving:Connect(function(descendant)
print(descendant.Name .. " è attualmente genitore di " .. tostring(descendant.Parent))
end)
local part = Instance.new("Part")
part.Parent = workspace
part.Parent = nil
--> La parte è attualmente genitore di Workspace
print(part.Parent)
--> nilDestroying
Campioni di codice
Utilizzo dell'evento di distruzione (segnali immediati)
local part = Instance.new("Part", workspace)
local function onPartDestroying()
print("Prima di aspettare:", part:GetFullName(), #part:GetChildren())
task.wait()
print("Dopo aver aspettato:", part:GetFullName(), #part:GetChildren())
end
part.Destroying:Connect(onPartDestroying)
part:Destroy()Utilizzo dell'evento Destroying (segnali differiti)
local part = Instance.new("Part", workspace)
local function onPartDestroying()
print("Nel segnale:", part:GetFullName(), #part:GetChildren())
end
part.Destroying:Connect(onPartDestroying)
print("Prima di distruggere:", part:GetFullName(), #part:GetChildren())
part:Destroy()
print("Dopo aver distrutto:", part:GetFullName(), #part:GetChildren())