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

How do i get the mass of an accessory?

Asked by
Zzverot 16
4 years ago

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?

0
:GetMass() is a function of BasePart. Syclya 224 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

: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
Ad

Answer this question