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