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

Help with print the mass of all parts in a model together?

Asked by
FiredDusk 1466 Moderation Voter
7 years ago

This script works but, I am not trying to do it individual. I am trying to get all the parts in a model and print the total mass of all together, not individual. I would appreciate the help!

local Parts = script.Parent:GetChildren()

local Table = {}
for i,Part in pairs(Parts) do
    table.insert(Table,Part)
end

for i,Value in pairs(Table) do
    if Value:IsA('Part') then
        print(Value:GetMass())
    end
end
0
Is this mass a string? NumberValue? Is it custom? Or your trying to get Roblox part mass? BlackOrange3343 2676 — 7y
0
part mass. FiredDusk 1466 — 7y
0
Have a variable "mass" and then in the loop just add to it, then print the end value? TheHospitalDev 1134 — 7y
0
Can u type out the code so I can see what u mean? FiredDusk 1466 — 7y
View all comments (2 more)
0
Yeah can't you just add to it? Like, mass = 0 for i,v in pairs(tab) do mass = mass + getmass() end print(mass) Perci1 4988 — 7y
0
You have over 1300 reputation and don't know how to use a variable? cabbler 1942 — 7y

2 answers

Log in to vote
2
Answered by 7 years ago

Have a variable, "Mass", and every time it loops, add to it then print it!

local Parts = script.Parent:GetChildren()

local Table = {}
for i,Part in pairs(Parts) do
    table.insert(Table,Part)
end

local mass = 0

for i,Value in pairs(Table) do
    if Value:IsA('Part') then
        mass = mass + Value:GetMass()
    end
end

print(mass)
Ad
Log in to vote
0
Answered by
joalars2 107
7 years ago
Edited 7 years ago

This should get the mass of every part in a model...

local mass = 0 --The initial mass. Will have to be reset for every new time you use getMassTotal()

function getMassTotal(v) --This function will repeat itself for every child of the selected object, and the children of that object, etc etc.
    if v:IsA("Part") then
        mass = mass + v:GetMass()
    end
    for _,b in pairs(v:GetChildren()) do
        getMassTotal(b)
    end
end

getMassTotal(model) --Replace model with whichever object you wish to search through.

^That should work rather well for searching for the masses of parts. You may want to add more types into the if v:IsA("Part") then though, as there are more than one type of part.

Examples: WedgePart, UnionOperation, TrussPart, Seat, and SkateboardPlatform.

And probably some more i forgot. Sorry if you didn't really 'learn' anything from this, I'm a terrible teacher.

But hey, atleast you can make use of it.

0
Woop Woop. joalars2 107 — 7y

Answer this question