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

How can i find the Weight of a Brick/Model?

O'k so i am making a script that will go into bricks, so anyway i want the script to activate a function when "OnTouched" then find how much pressure is being put on the brick, and then if it goes past the limit ":BreakJoints()" so how can i find how much pressure/weight is being put on the brick?

1 comment

0

Just use the size. It will be simpler that way.

1 answer

✓ Accepted answer

Depends on your definition of weight. I will assume you mean mass, but if you want the force of gravity exerted by the brick/model, simply multiple the mass by the acceleration do to Gravity (game.Workspace.Gravity, where 196.2 is the default).

Calculating Mass

Getting the mass of a part is simple, as they all have the function GetMass.

As for getting the mass of a model, we are going to need a custom function for that. All you have to do is look for every descendant that inherits from BasePart and sum together the mass of all of these objects. This is most easily done using recursion:

function GetDescendantMass(parent)
	local sum = 0

	for _, child in ipairs(parent:GetChildren()) do
		if child:IsA("BasePart") then
			sum = sum + child:GetMass()
		end
		sum = sum + GetDescendantMass(child)
	end

	return sum
end

To use this function simply pass in the model you want to get the mass of as the argument.

4 comments

0

Ah i see i did not know we had a GetMass function, thanks a lot

0

And as for getting the weight of everything on the part, I would recommend using a region3 positioned just above. Use workspace:FindPartInRegion3() counting only the parts inside that are unanchored and have no y velocity.

0

The Region3 wouldn't be perfect either; imagine a box sitting atop another box which is sitting on the button. The problem gets tricky here because you then have to consider the forces applied on parts applying force on the button.

0

I don't think so. There's no better solution anyway.

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