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

Help with cloning multiple things together?

Asked by 8 years ago

Here is the code:

player = script.Parent.Parent 
player.CanLoadCharacterAppearance = false 
character = player.Character
character.Head.BrickColor = BrickColor.new("Bright yellow")
character.Torso.BrickColor = BrickColor.new("Bright yellow")
character["Left Arm"].BrickColor = BrickColor.new("Bright yellow")
character["Right Arm"].BrickColor = BrickColor.new("Bright yellow")
character["Left Leg"].BrickColor = BrickColor.new("Bright yellow")
character["Right Leg"].BrickColor = BrickColor.new("Bright yellow")


game.ServerStorage.farmer:GetChildren():Clone().Parent = character


It keeps erring, saying that Clone is a nil value, but I clearly assigned the parent of character to the clone. Anyways, it would be great to help with this and also is there an easier way to color the character's body colors without doing each and every part?

Thanks in advanced

1 answer

Log in to vote
1
Answered by 8 years ago

The problem is that GetChildren() returns a table containing the children, but Clone() can only be called on an individual child. You need to loop through the table and call Clone() on each child, like this:

for i, v in ipairs(game.ServerStorage.farmer:GetChildren()) do
    v:Clone().Parent = character
end
0
How is GetChildren() useful? TSK_Uncovered 55 — 8y
0
Also, what does i, v in pairs do/mean . Could i use different letters? TSK_Uncovered 55 — 8y
0
Yes IDidMakeThat 1135 — 8y
Ad

Answer this question