Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to :GetMass() of a model?

Asked by
lucas4114 607 Moderation Voter
8 years ago

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

1 answer

Log in to vote
3
Answered by
drew1017 330 Moderation Voter
8 years ago

Please provide explanation with your answers. Simply posting code does not spread knowledge of integral scripting processes which helps people understand the logic and reasoning behind your 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.

0
You made a small mistake. Remove the return statement out of the loop. Lacryma 548 — 8y
0
orite drew1017 330 — 8y
0
What does the i and the v mean in your script? I wanna know so I can script better! james24dj 90 — 8y
View all comments (7 more)
0
Replace IsA("Part") with IsA("BasePart"), that way it'll get the mass of wedges, balls, and other base parts as well. grasheeno 70 — 8y
0
right, forgot drew1017 330 — 8y
0
Aren't Unions also a basepart? YellowoTide 1992 — 8y
0
poor drew funyun 958 — 8y
0
no, they are UnionOperations unmiss 337 — 8y
0
pretty sure Union works as an abbreviation drew1017 330 — 8y
0
They are UnionOperations, but they extend BasePart anyway. BlueTaslem 18071 — 8y
Ad

Answer this question