How to get total mass of a model?

Exactly what the title is asking, what is the easiest way to get the total mass of a model?

2 Likes

Currently, I am unsure if you are able to.
But you might want to refer to this post however.

1 Like

ROBLOX has a really neat, built in method for parts: :GetMass().

Using this knowledge, we can write a function:

function getMass(model)
    assert(model and model:IsA("Model"), "Model argument of getMass must be a model.");
    local mass = 0;
    for i,v in pairs(model:GetDescendants()) do
        if(v:IsA("BasePart")) then
            mass += v:GetMass();
        end
    end
    return mass;
end

EDIT: Updated to use AssemblyMass propery of BaseParts:

function getMass(model)
    assert(model and model:IsA("Model"), "Model argument of getMass must be a model.");
    local mass = 0;
    for i,v in pairs(model:GetDescendants()) do
        if(v:IsA("BasePart")) then
            mass += v.AssemblyMass;
        end
    end
    return mass;
end
16 Likes

What’s the difference between the assemblymass and the getmass?

1 Like

According to the Developer wiki, AssemblyMass has a feature where “parts that are Massless and are not the assembly’s root part will not contribute to the AssemblyMass.” Be advised that AssemblyMass also considers anchored parts to have infinite mass.

10 Likes

Sorry for the bump, but how and where do i reference my model? And Im looking to print the locomotives total mass into my output. How would I be able to do that?