How can I ungroup all of the models in the folders, parent them to workspace, and then delete all of the folders?

image

So I have multiple folders with the same name. They all contain models with the same name. How would I ungroup all of the models in all of these folders, and then delete the folder and just make everything belong to the workspace?

script in the screenshot does not work, I put it in the command bar and it did nothing.

What you could do is:

local Bush = game.Workspace:GetChildren("Bush")

for _,child in ipairs(Bush) do
    if child.Name == "Bush" and child:IsA('Model') then
        child.Parent = workspace
        _:Destroy()
    end
end)

I don’t know of a way to ungroup models via script

for i, v in pairs(game.Workspace:GetChildren()) do
    if v.Name == “Bush” then
        for k, j in pairs(v:GetChildren()) do
            for a, b in pairs(j:GetChildren()) do
                b.Parent = game.Workspace
            end
        end
    end
end

Now i know this is probably not the easiest way, and is kind of confusing, but i think that will go through each folder and model and set the part’s parent to the workspace.

Let me know if this is helpful :slightly_smiling_face:

Didn’t work got this error

image

The problem is with the quotes. Switch the quotes @Carl_Weezer13 used with normal quotes from your keyboard. I’m surprised you didn’t catch that detail but I guess things can be a little tricky.

oh yeh that worked I deleted the quotes and used ’ ’

Thank you!

Screenshot of working script.

for i, v in pairs(game.Workspace:GetChildren()) do
	if v.Name == 'Bush' then
		for k, j in pairs(v:GetChildren()) do
			for a, b in pairs(j:GetChildren()) do
				b.Parent = game.Workspace
			end
		end
	end
end

Oh, sorry I didn’t see that lol. I’ll keep that in mind :sweat_smile:

Here you go. :slight_smile:

for _, Folder in pairs(workspace:GetChildren()) do
	if Folder:IsA("Folder") and Folder.Name == "Bush" then
		for _, Model in pairs(Folder:GetChildren()) do
			for _, Child in pairs(Model:GetChildren()) do
				Child.Parent = workspace
			end
		end
		Folder:Destroy()
	end
end

How come you would ungroup the models?

Thank you!!! I’m putting all of the flower blocks into 1 folder. Inside all of these folders there are also grass blocks. I’m going to put all of the grass blocks into another folder. I then have 2 scripts that are going to go inside of these 2 folders and put a bush where all of the grass blocks are placed, and a type of flower or mushroom where all of the flower blocks are placed.

You should mark his as a Solution because he gave you the solution.

I’m sure it’s not as complicated as it sounds. Good luck with your project