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

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

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

6 comments

0

Is this mass a string? NumberValue? Is it custom? Or your trying to get Roblox part mass?

0

part mass.

0

Have a variable "mass" and then in the loop just add to it, then print the end value?

0

Can u type out the code so I can see what u mean?

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)

0

You have over 1300 reputation and don't know how to use a variable?

2 answers

✓ Accepted answer

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)

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.

1 comment

0

Woop Woop.

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