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

How do i clone the children of a model?

Asked by 6 years ago

Basically, what the title says.

I want to do something to change the StarterPlayer after touching a part, and to do so, i tought of doing a script like this

script.Parent.TouchEnded:connect(function(part)
    local Content = script.Parent.Parent.TransformContent
    local Player = part.Parent:FindFirstChild("Humanoid")
    if Player == nil then return end
    Player.Parent:ClearAllChildren()
    local Morphing = Content:Clone()
    Morphing.Parent = Player.Parent
end)

Note: check this image to understand this better -http://prntscr.com/j9l5bs

However, the script dint work as i tought. So, can us tell me how to clone the Children of "TransformContent" to the Player's Parent (aka: The player's model that gets empty after the "clearallchildren" on the script), please?

Also, Yes, i know that brick isnt rigged and it wont work as a starterplayer, is just that ill rig it later. Second, No, this isnt for a roleplay or something like that, its for a minigame game that uses cubes with eyes as the main characters.

1 answer

Log in to vote
0
Answered by 6 years ago
script.Parent.TouchEnded:connect( function(part)
    local Contents = script.Parent.Parent.TransformContent:GetChildren()
    local Character = part.Parent
    if not Character:FindFirstChild("Humanoid") then return end
    Character:ClearAllChildren()
    for i,content in pairs(Contents) do
        local Clone = content:Clone()
        Clone.Parent = Character
    end
end)
0
Making use of the GetChildren() function and the 'pairs' loop. Le_Teapots 913 — 6y
Ad

Answer this question