What's the best way to get all the descendants of a model server-side?

So what I have currently tried is using Remote Events and then tried using Remote Functions(I perhaps struggled with properly utilizing remote functions for this since I did attempt to make the scripts communicate)
I want to make a script ‘iterate’ through a model getting the light and well from there allowing me to change it for the server as I like once a player has pushed a UI TextButton

Currently it’s just printing “nil” instead of the descendants names.

If you’re just changing a light can’t you put it somewhere more plausible? If you want to turn it on for the server use a RemoteEvent, if you want to turn it on for the just the player, use the local script.

I’m trying to turn on a group of lights for the server but it’s not working, not just one light. It prints “nil” regardless of what event I use.
I used
I can replicate the original code(WITH the event) before I attempted another method if it would be helpful.

local descendants = game.Workspace.Cell_Lighting:GetDescendants()

for index, descendant in pairs(descendants) do

print(descendants.Name)

return descendants

end
1 Like

Ahh, gotcha. So are they all in one model/folder, or are they spread out?

If they are all in one model, fire a RemoteEvent to the server that loops through the model’s children (or wherever the lights are) and proceed to do what you wish, turn them on, etc.

for _, Model in pairs(game.Workspace.Cell_Lighting:GetChildren()) do

if Model.Name == “Light” then

–blah blah

end

end

print(descendants.Name) should be print(descendant.Name). descendants is the array of descendants you’re iterating through.

return descendants should also be removed, otherwise your code will stop executing at the scope level.

1 Like

Trying to fire this from a button though so I think it requires a RemoteEvent but whenever I use one it just comes out as '“Nil(x[Numbers]”

I’ll send the full original code including what was in the event

Yeah, like byc14 said. You have a variable called “descendants”, and you’re trying to return that instead of the “descendant”

Change that, and you should be fine.

Sorry, I misunderstand your question.

1 Like

Ah thank you, was probably just a typo on my behalf (rather stupid). Appreciated the help

1 Like

There’s your typo. You’re indexing Name from descendants, with the S. This is referring to your table of descendants rather than the object itself. You’re seeing nil because it doesn’t have an index called Name. Only objects indexed by numbers.

Edit: Oops. I didn’t realize the other response was saying essentially the same thing.