Ungrouping parts

Hey whats up guys, I need help scripting a part that when a specific model touches it, the model ungroups.

Now I got no skills in scripting, so if you supply a script, give me an explanation of what the main lines of coding in it do.

Thanks!

2 Likes

You can use the Touched event in one of the parts in the model.
And when touched, loop through the children in the model, and put them in the parent of the model.

local model = nil --Replace nil with your model path
script.Parent.Touched:Connect(function() --If the script is in the part, if not, change the script.Parent to the path
	for i,v in pairs(model:GetChildren()) do --Loop through the children
		v.Parent = model.Parent --Place them in the model's parent.
	end
end)

Should be done something like this.
I guess that instead of the model’s path you can use something like :FindFirstAncestorWhichIsA(“Model”), but use it only if the part is in one model.
Like this:

local model = script:FindFirstAncestorWhichIsA("Model") --If the script is in the part and only have 1 parent model
3 Likes
-- sample code. Put in part
script.Parent.Touched:Connect(function())
   for i,v in pairs(script.Parent.Parent:GetChildren()) do
      v.Parent = workspace
   end
   script.Parent.Parent:Destroy()
end)

Let me know if it doesn’t work

1 Like

This won’t work because GetChildren returns an array not a roblox instance

2 Likes

Bruh I’m so dumb… Thanks for pointing that out, I fixed it

2 Likes