Character:GetChildren ignores some instances?

Im trying to get the children of the player but it only gets certain children and ignores the rest

my code
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Char = Player.Character or Player.CharacterAdded:Wait()

for i,v in pairs(Char:GetChildren()) do 
	print(v) -- this is what is printing (line 16)
	if v.ClassName == "Accessory" then
		print(v) -- this isnt printing because it wont get that type of child
	end
end
output
12:53:08.245  Head  -  Client - LocalScript:16
12:53:08.247  Torso  -  Client - LocalScript:16
12:53:08.248  Left Arm  -  Client - LocalScript:16
12:53:08.249  Right Arm  -  Client - LocalScript:16
12:53:08.250  Left Leg  -  Client - LocalScript:16
12:53:08.252  Right Leg  -  Client - LocalScript:16
12:53:08.253  Humanoid  -  Client - LocalScript:16
12:53:08.254  HumanoidRootPart  -  Client - LocalScript:16
12:53:08.255  LocalScript  -  Client - LocalScript:16
12:53:08.256  LocalScript  -  Client - LocalScript:16
my character (what it should be printing)

image

It most likely happens because some assets haven’t loaded yet by the time the script runs.

1 Like

If you look at LoadCharacter, you’ll see that CharacterAdded fires before the appearance is loaded. The linked documentation lists the following order of events when a character is loaded:

So you will need to use WaitForChild or some sort of method to wait for the necessary items.

3 Likes

Thanks! Used Player.CharacterAppearanceLoaded:Connect(function() to yield until everything has loaded :))

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.