I want to know how to loop through a character’s properties using a for in loop and only get their body parts. When I did it it stopped at the first one index. Can any of you help me?
I don’t think you could get a table of an instance’s property, unless there’s like a function to do that.
If you’re wanting to get their parts
from character model, use:
for _, i in pairs(char:GetChildren()) do --for each child in their character do
if i:IsA("BasePart") then --if child is a part of the body then
--code here
end
end
Extending from @Doqee’s response:
Instead of checking if the object is a BasePart, you could check if it’s a part. I’ve personally tried checking for BasePart and it didnt work but checking for Part did.
for _, part in pairs(character:GetChildren()) do -- Doing a for loop that runs for every single object in the character. The part variable is the object the loop is currently on.
if part:IsA("Part") then -- Check if the object is a part (A character's arm, head or leg)
-- Your Code
end
end
That’s incorrect. Checking for a part
is like checking for HumanoidRootPart
, hence other body parts are MeshParts
, and in some cases, Parts
. This depends on what avatar version it is on. BaseParts
are anything between these 2.
It worked. Thanks for the help everybody!
How do you do this, but you only find specific character body parts? (Example: Looping through to only reference the UpperTorso, RightHand, LeftHand, RightFoot, and LeftFoot.)
use:
if part:IsA("LeftArm") or part:IsA("RightArm") then
replacing all the parts you want