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

How do i clone the children of a model?

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

✓ Accepted answer
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)

1 comment

0

Making use of the GetChildren() function and the 'pairs' loop.

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