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 5 years ago
Edited 5 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!

01--There are other pieces of code above
02 
03event3.OnInvoke = function()
04    local AIScripts = game.workspace:GetDescendants()
05          for i=1, #AIScripts do
06            if AIScripts[i]:IsA("Model") then
07                if AIScripts[i].Name == "AI" then
08                if AIScripts[i]:IsA("Script") then
09                    AIScripts[i].Disabled = false
10        end
11    end
1
Use :GetDescendants() Ziffixture 6913 — 5y

2 answers

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

You will use an in pairs loop

1for i, AWorkspacePart in pairs(game.Workspace:GetDescendants()) do
2    if AWorkspacePart:IsA(Model) and AWorkspacePart:FindFirstChild(AIScript) then
3        AWorkspacePart:FindFirstChild(AIScript).Disabled = false
4    end
5end
Ad
Log in to vote
0
Answered by 5 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