How do I Unanchor multiple parts efficiently?

Hello,
I want to unanchor many parts in a model, but don’t know an efficient way to do it. I know I could use a for loop but that wouldn’t be efficient. All parts are welded together.

In this case, I’m making a nuke simulator game, and I’m trying to make it drop.
image

You could have one root part that’s anchored, and then you could weld every other part in the nuke to that anchored part. Then unanchor it and bombs away :slight_smile:

1 Like

If you have a root part and you’re welding the parts, then just unanchor the root part, otherwise, you can do something like this:

local Model = workspace.Model -- Or where the model is
for _, Part in ipairs(Model:GetDescendants()) do -- ipairs cause it's an array not a dictionary
  if Part:IsA("BasePart") then -- Check if it is a part, not a model or something that can't be unanchored
    Part.Anchored = false -- All hail the unanchor
  end
end

I will say this won’t be as neat as welding it though

1 Like

Alright, I’m going to try that rq!

1 Like

That doesn’t quite seem to do the job, I’m not good at welding :sweat_smile:

Maybe I can union the parts into several groups (there’s 139 and manually welding them would take an eternity) and weld them instead?

I’m also using a welding plugin.

1 Like

So if your nuke is completely welded together, just choose any single part to be the ‘root’ part, and anchor it. Then unanchor it when you want it to drop.

Look at what @Kryptonilite replied with. That’ll help ya.

1 Like

There’s something weird going on. I unanchored all the parts in the model, but the bomb doesn’t drop.


It’s also acting weirdly. Take a look: https://i.gyazo.com/95df1aa7217c3a6569e89f1aa956bf8b.mp4

If you un-anchor the parts, they will fly and distort away from the original nuke shape unless they are all welded together.

The strategy above would work, though it’s not a very good way to do it, especially since it isn’t timed and pre-set. The physics of roblox could make this strategy an inefficient way to do it.

Instead use tween service. You could weld all parts in the nuke together using primary part as weld root, and then you could tween the primary part to a specific position, and do your nuke blast event like that.

To weld all parts together with primary part as weld root, you could do:

for _, Part in ipairs(Model:GetDescendants())do

	if Part:IsA("BasePart") or Part:IsA("Part") or Part:IsA("MeshPart") and not Part.Name == "NukePrimaryPart" then
		
		local newWeld = Instance.new("WeldConstraint", Model.PrimaryPart)
		newWeld.Name = Part.Name
		newWeld.Part0 = Model.PrimaryPart
		newWeld.Part1 = Part
		
	end

end   

Make sure your models PrimaryPart isn’t nil, and is set to a part called “NukePrimaryPart”

Now you can tween your models primary part to the ground, and when the tween finishes you can do your nuke event.

Note: Make sure the code above is in a server script obviously, and make sure you do the tweening and event in a server script.

Because you did it on the client. When you do stuff locally it doesn’t seem to work.

If you do want it to work, click this little button in the studio “Test” tab:

image

Then do whatever you want in there, and it’ll do stuff in the server instead of the client while your game is running.

To switch back click the button again.

I have found a fix to the problem. I put the unanchored version of the bomb in ServerStorage, and replaced the anchored one with it. Sorry for wasting your time :confused:

Ha, good job :grinning_face_with_smiling_eyes:

Don’t worry, I’m always here to help. You didn’t waste my time!

1 Like

Thanks, I thought I kind of did, but once again, thanks for helping me! :smile:

Again, I would still use tweenservice instead of un-anchoring the parts.

Thoughhhhh…

I just realized that you could loop through everything in workspace, and when the nuke model or a part inside of it touches any of those parts in workspace…

Kaboom!

1 Like

You would most likely need a hitbox on your nuke to do this though. That would make it much easier.

image
It’s working so I guess I don’t need to change anything. :smile: