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

How do i get the mass of an accessory?

I'm trying to stop the player from falling, and for this i need to get the players mass. I can get the mass for most of the parts, but on the hat it outputs "GetMass is not a valid member of Accessory". Heres the script i'm using.

local character = player.Character
local plrMass = 0
	
for i, part in pairs(character:GetChildren()) do
	if part:IsA("BasePart") or part:IsA("Accessory") then
		plrMass = plrMass + part:GetMass()
	end
end

How do i fix this?

1 comment

0

:GetMass() is a function of BasePart.

1 answer

✓ Accepted answer

:GetMass is only applicable to BaseParts. An accessory is just a container; it itself doesn't have any mass. You need to iterate through all BaseParts in the accessory and add on their mass.

Use :GetDescendants() instead of :GetChildren():

for i, v in pairs(character:GetDescendants()) do
    if v:IsA("BasePart") then
        -- add on v:GetMass()
    end
end

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