How to get all children which are NOT a script

Yeah, title basically says it all. I want to know if there is a way to get all children of a model which aren’t a script.

1 Like

You can get all children that isn’t a type of script by checking if an object inherits from LuaSourceContainer superclass or not:

local Object = --[[Instance path]]
local FilteredChildren = {}

for Index, Value in ipairs(Object:GetChildren()) do
    if Value:IsA("LuaSourceContainer") == false then
        table.insert(FilteredChildren, Value)
    end
end
1 Like

Yeah sorry, what does the table.insert(FilteredChildren, Value) line do?

It just adds the Instance that isn’t a LuaSourceContainer to the end of the FilteredChildren table.

image It doesnt work

Can you tell us the reason why you think it doesn’t work?

I typed it wrong?
character limit

It’s an example. A better way to show it is this:

local group = workspace.Group

for index, child in pairs(group:GetChildren())
  if not child:IsA(“Script”) then
    script goes here
  end
end

This script loops through the group and will filter out all of the scripts.

That really doesn’t explain your problem. Does the code output an error in console or it just doesn’t run at all or is it something else?

Your script looks like it would work. What are you trying to do with the filtered children? Don’t forget that you need to loop through the table to be able to do something with them.

It doesn’t run, but it doesn’t show an error either

for i,v in pairs(model:GetChildren()) do
     if not v:IsA("Script") then -- Checks if child's class is not a script
     -- Do something
     end
end

This should work

If you think that the code doesn’t run, then it could be that an infinite loop is preventing it from running. An infinite loop will forever repeat its code causing code below it to never run. How do you think that the code doesn’t run though? (Also if you would like to test if the code doesn’t run, then you can test it by adding print statements like this:

for i,v in pairs(model:GetChildren()) do
     if not v:IsA("Script") then
         print("code is running")
         -- Do something with the children here
     end
end

if a print appeared on your output tab, then that means the code is working.

(This is a different code from before which @aeroplanepoo provided, and it allows you to make changes on the children already without having to use tables so all you need to do is to put your code that will do something to the children inside the loop)

Nevermind the post is already solved xD