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

How to :GetMass() of a model?

I know how to do it to a part but how do I do it to a model..?

1 answer

✓ Accepted answer
function GetMassOfModel(model)
	local mass = 0
	for i, v in pairs(model:GetChildren()) do
		if v:IsA('BasePart') or v:IsA('Union') then
			mass = mass + v:GetMass()
		end
	end
	return mass
end

Something like that; When this function is called on a model (as the argument), it iterates through each object in the model specified, checks if it's a physical object, and then adds that object's mass into a total (the mass variable), returning the variable when it's done iterating.

11 comments

0

You made a small mistake. Remove the return statement out of the loop.

0

orite

0

What does the i and the v mean in your script? I wanna know so I can script better!

0

Replace IsA("Part") with IsA("BasePart"), that way it'll get the mass of wedges, balls, and other base parts as well.

0

right, forgot

0

Aren't Unions also a basepart?

0

poor drew

0

no, they are UnionOperations

0

pretty sure Union works as an abbreviation

0

They are UnionOperations, but they extend BasePart anyway.

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