Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I get the children of GetChildren()?

Asked by 4 years ago
Edited 4 years ago

Alright so, I would like set to the scripts inside a model (which is parented to workspace) to Disabled = false when an event is fired, however I am stuck on how I would access these scripts using a for loop.

I currently have the script below but it doesn't seem to work.

Any help would greatly be appreciated!


--There are other pieces of code above event3.OnInvoke = function() local AIScripts = game.workspace:GetDescendants() for i=1, #AIScripts do if AIScripts[i]:IsA("Model") then if AIScripts[i].Name == "AI" then if AIScripts[i]:IsA("Script") then AIScripts[i].Disabled = false end end
1
Use :GetDescendants() Ziffixture 6913 — 4y

2 answers

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

You will use an in pairs loop

for i, AWorkspacePart in pairs(game.Workspace:GetDescendants()) do
    if AWorkspacePart:IsA(Model) and AWorkspacePart:FindFirstChild(AIScript) then
        AWorkspacePart:FindFirstChild(AIScript).Disabled = false
    end
end
Ad
Log in to vote
0
Answered by 4 years ago

:GetDescendants() should already tell you every childrens' child (if that makes sense). Using :GetDescendants() is the same as using :GetChildren():GetChildren() (If that actually was a working thing)

Answer this question