How to ungroup a model and folder via code?

I have a ticket machine model which has auto updates (it needs to insert a model and it has all the files) however, the files come inserted in a group. How can I ungroup them via a script?

image
All the frames and scripts you see under the folder are not supposed to be there. They need to parent a surfacegui.

Something that would also work is making the children a parent of the surfacegui, but I don’t know how to start on this.

function ungroupAndParent(folder:Instance, newParent:Instance)
for _, obj in folder:GetChildren() do
obj.Parent = newParent
end
end

You could also do obj:Clone().Parent = newParent to clone the item instead of reparenting directly.