How do i get all children

hey everybody :smiley:
Is there a way that I can get all children and change their properties at once?
and how would i go about doing this?

15 Likes
local Children = game.workspace.Model:GetChildren()

for i = 1, #Children do
   Children[i].Color = Color3.fromRGB(255, 0, 0)
end
20 Likes

Just adding on to the previous solution on this thread, here is the API reference, just thought it could be handy for you

4 Likes

to get children you do

stuff=thing:GetChildren()

to do stuff with them you do this

for i = 1, #stuff do
   stuff[i]---
end

you must use

  stuff[i]

so script will know with what to work

2 Likes

Actually instead of naming it as thing you can name it as Instance :slight_smile: Just saying btw.

3 Likes

yeah ik but it doesnt seem to work since im enabling beams from a script but it is inside a charactermodel do scripts run in charactermodels?

Scripts do run as long as they are a descendant of workspace too, so I donā€™t really know why its not working unless I can see the code.

local Children = script.Parent.ReentryFlames:GetChildren()

for i = 1, #Children do

Children[i].Enabled = true

end

Are you sure the property Enabled isnā€™t changing?

Also try using this loop, if its not working still.

local Children = script.Parent.ReentryFlames:GetChildren()

for i,v in pairs(Children) do
   v.Enabled = true
end

its not working however the origins of the script is in the startercharacter in starterplayer could that be why?

Oh. Yeah, I would recommend it removing from there, as they only work if they are a descendant of ServerScriptService or Workspace.

You could place it in the model too, if it meets your requirements?

place it in what model. however it already is in the startercharacter

Check where it is. If it isnā€™t workspace and itā€™s a workspace-type entity then it wont work or show up. Iā€™m pretty sure a ā€œbeamā€ instance needs to be in workspace for it to work.

Likewise what @WaterJamesPlough said, Check the value. Is it active when you set it to active. Is it not when you set it to not?

What are the ā€œchildrenā€ can you show us an image or some sort of visualisation of the explorer. And the children the script is trying to access

1 Like

Do you want to get the children of children as well? If so do this:

All Decendants Script
for _, v in ipairs (script.Parent.ReentryFlames:GetDecendants()) do 
   if (v:IsA("Beam"))  then
       v.Enabled = true
  end
end

The ones above arent working because there trying to set all children, not just beams.

You canā€™t call an instance as a function. This will error.

2 Likes

Actually, why did you edit the post? It was fine when it was :GetDescendants method on the instance itself.

1 Like

Oops. I deleted more than I meant to lol. Sorry! Iā€™ll fix it.