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

How to clone an object with it's children?

I am making a script that would clone a ball and it’s effects (children) to the workspace.


NRGremoteEvent = game.ReplicatedStorage.nrgEvent

NRGremoteEvent.OnServerEvent:Connect(function(plr)
  local NRGclone = game.ReplicatedStorage.NRGfolder.EnergyBmain:Clone()

  NRGclone.Parent = game.Workspace
  NRGclone.Position = Vector3.new(0,30,30)
end)

The thing is, that it only clones the main (EnergyBmain). It doesn’t clone it’s children which are particles and such. They’re stored in a folder (NRGfolder) and is located inside ReplicatedStorage. I’m very lost on what to do, i can’t find a way to clone the whole thing (main and children), please help. Thanks.

(on mobile rn.)

1 comment

0

im even more lost as to why its only cloning the object and not the descendants, a variety of reasoning behind this. for example if you clone a single object on server and have its descendants on client

1 answer

NRGremoteEvent = game.ReplicatedStorage.nrgEvent

NRGremoteEvent.OnServerEvent:Connect(function(plr)
    local NRG = game.ReplicatedStorage.NRGfolder.EnergyBmain:GetChildren()
    for i, v in pairs(NRG) do
        wait()
        local NRGclone = v:Clone()
        NRGclone.Parent = game.Workspace
        NRGclone.Position = Vector3.new(0,30,30)
    end
end)

So what I did was I gathered the children, and cloned them one by one in a for in pairs() loop.

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