Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I get the children of GetChildren()?

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 comment

1

Use :GetDescendants()

2 answers

✓ Accepted answer

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

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

This discussion is preserved as it was. New answers, comments, and votes are closed.