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?
How can i find the Weight of a Brick/Model?
1 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
Ah i see i did not know we had a GetMass function, thanks a lot
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.
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.
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.

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