Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to Get Children?

Asked by 8 years ago

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

Log in to vote
2
Answered by
Shawnyg 4330 Trusted Badge of Merit Snack Break Moderation Voter Community Moderator
8 years ago

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)
Ad
Log in to vote
1
Answered by 8 years ago
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?

0
Always try add an explanation to help the person. Posting code will make the person not understand what they did wrong. TheHospitalDev 1134 — 8y

Answer this question