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