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

How to Get Children?

How could I get all the children from inside a model together so I don't have to make a variable for each body part?

local Fire = game.ServerStorage.Parts:GetChildren() -- NEED TO GET CHILDREN FROM INSIDE THIS MODEL
local firecopy = Fire:Clone()

game.Players.PlayerAdded:connect(function(player)
	player.CanLoadCharacterAppearance = false 
	wait()
	firecopy.Parent = player.Character
end)

The error is occurring on the first line because I can't select all the children to clone. Part is a model in server storage with package parts. Thanks.

2 answers

✓ Accepted answer

Nice try! When you use GetChildren, it practically returns a table, filled with all of the 'children' as its values. Ex:

local a = model:GetChildren()
-- Above would look like: {Apple, Button}

To 'break' the table, you'll need to use a generic or numeric for loop, but in this case, is a generic for loop. I'll show you:

local Fire = game.ServerStorage.Parts

game.Players.PlayerAdded:connect(function(player)
    player.CanLoadCharacterAppearance = false 
    wait()
    for i,v in pairs(Fire:GetChildren()) do -- iterates through all of its children
        v:clone().Parent = player.Character -- clones it and puts it in the player's character
    end
end)
local Fire = game.ServerStorage.Parts:GetChildren() -- NEED TO GET CHILDREN FROM INSIDE THIS MODEL
for i = 1, #Fire do
local firecopy = Fire[i]:Clone()
game.Players.PlayerAdded:connect(function(player)
    player.CanLoadCharacterAppearance = false
    wait()
    firecopy.Parent = player.Character
end
end)

--That's what my guess would be?

1 comment

0

Always try add an explanation to help the person. Posting code will make the person not understand what they did wrong.

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