Using loop to detect players children but accessories are not being shown

I have a for loop that I’m using to go through all the players children to find accessories so I can (eventually) add them to a global ignore list so raycasts cannot hit them, but for some reason its not getting the accessories of my player, just every single other child.

script

local function onPlayerJoin(player)
	print('hiya')
	local char = player.Character
	local accessory = char:GetChildren()
	if player.CharacterAppearanceLoaded then
	for i, part in pairs(accessory) do
		print(part)
		if part:IsA("Accessory") then
				print(part,"1")
			end
		end
	end
end

game.Players.PlayerAdded:Connect(onPlayerJoin)
for _,player in pairs(game.Players:GetPlayers()) do
	onPlayerJoin(player)
end

console output:

  20:14:49.257  hiya  -  Server - Server:19
  20:14:49.257  HumanoidRootPart  -  Server - Server:24
  20:14:49.257  LeftHand  -  Server - Server:24
  20:14:49.257  LeftLowerArm  -  Server - Server:24
  20:14:49.257  LeftUpperArm  -  Server - Server:24
  20:14:49.257  RightHand  -  Server - Server:24
  20:14:49.257  RightLowerArm  -  Server - Server:24
  20:14:49.257  RightUpperArm  -  Server - Server:24
  20:14:49.257  UpperTorso  -  Server - Server:24
  20:14:49.257  LeftFoot  -  Server - Server:24
  20:14:49.257  LeftLowerLeg  -  Server - Server:24
  20:14:49.257  LeftUpperLeg  -  Server - Server:24
  20:14:49.257  RightFoot  -  Server - Server:24
  20:14:49.258  RightLowerLeg  -  Server - Server:24
  20:14:49.258  RightUpperLeg  -  Server - Server:24
  20:14:49.258  LowerTorso  -  Server - Server:24
  20:14:49.258  Humanoid  -  Server - Server:24
  20:14:49.258  Head  -  Server - Server:24
  20:14:49.258  Health  -  Server - Server:24
  20:14:49.258  Animate  -  Server - Server:24
  20:14:49.258  Body Colors  -  Server - Server:24

Instead of
print(part,"1")
try
print(part.Name)
Really the only thing I can think of, I don’t see any errors in the rest of the code

1 Like
local function onPlayerJoin(player)
	print('hiya')
	local char = player.Character or player.CharacterAdded:Wait()

	if player.CharacterAppearanceLoaded then
		for _, part in pairs(char:GetChildren()) do
			if part:IsA("Accessory") then
				print(part.Name)
			end
		end
	end
end

game.Players.PlayerAdded:Connect(onPlayerJoin)
for _, player in pairs(game.Players:GetPlayers()) do
	onPlayerJoin(player)
end

does this work?

1 Like

It still does the same thing in the console

  20:37:55.965  hiya  -  Server - Server:19
  20:37:55.965  HumanoidRootPart  -  Server - Server:24
  20:37:55.965  LeftHand  -  Server - Server:24
  20:37:55.965  LeftLowerArm  -  Server - Server:24
  20:37:55.966  LeftUpperArm  -  Server - Server:24
  20:37:55.966  RightHand  -  Server - Server:24
  20:37:55.966  RightLowerArm  -  Server - Server:24
  20:37:55.966  RightUpperArm  -  Server - Server:24
  20:37:55.966  UpperTorso  -  Server - Server:24
  20:37:55.966  LeftFoot  -  Server - Server:24
  20:37:55.966  LeftLowerLeg  -  Server - Server:24
  20:37:55.966  LeftUpperLeg  -  Server - Server:24
  20:37:55.966  RightFoot  -  Server - Server:24
  20:37:55.966  RightLowerLeg  -  Server - Server:24
  20:37:55.966  RightUpperLeg  -  Server - Server:24
  20:37:55.966  LowerTorso  -  Server - Server:24
  20:37:55.966  Humanoid  -  Server - Server:24
  20:37:55.966  Head  -  Server - Server:24
  20:37:55.967  Health  -  Server - Server:24
  20:37:55.967  Animate  -  Server - Server:24
  20:37:55.967  Body Colors  -  Server - Server:24

I edited it try again
I removed a print()

1 Like

I tried this as well and it stopped running after
print(“hiya”)

Turns out I was getting the players children too quickly in the code lol

updated script:

local ignore = {}

local function onPlayerJoin(player)
	print('hiya')
	local char = player.Character
	repeat wait() until player:HasAppearanceLoaded()
	local accessory = char:GetChildren()
		for i, part in pairs(accessory) do
			print(part)
			if part:IsA("Accessory") then
			table.insert(ignore, part)
			print(ignore)
			end
		end
	end


game.Players.PlayerAdded:Connect(onPlayerJoin)
for _,player in pairs(game.Players:GetPlayers()) do
	onPlayerJoin(player)
end

updated console output:

  21:02:06.039  HumanoidRootPart  -  Server - Server:25
  21:02:06.039  LeftHand  -  Server - Server:25
  21:02:06.039  LeftLowerArm  -  Server - Server:25
  21:02:06.039  LeftUpperArm  -  Server - Server:25
  21:02:06.039  RightHand  -  Server - Server:25
  21:02:06.039  RightLowerArm  -  Server - Server:25
  21:02:06.039  RightUpperArm  -  Server - Server:25
  21:02:06.039  UpperTorso  -  Server - Server:25
  21:02:06.039  LeftFoot  -  Server - Server:25
  21:02:06.039  LeftLowerLeg  -  Server - Server:25
  21:02:06.039  LeftUpperLeg  -  Server - Server:25
  21:02:06.040  RightFoot  -  Server - Server:25
  21:02:06.040  RightLowerLeg  -  Server - Server:25
  21:02:06.040  RightUpperLeg  -  Server - Server:25
  21:02:06.040  LowerTorso  -  Server - Server:25
  21:02:06.040  Humanoid  -  Server - Server:25
  21:02:06.040  Health  -  Server - Server:25
  21:02:06.040  Animate  -  Server - Server:25
  21:02:06.040  Body Colors  -  Server - Server:25
  21:02:06.040  Head  -  Server - Server:25
  21:02:06.040  Pants  -  Server - Server:25
  21:02:06.040  Shirt  -  Server - Server:25
  21:02:06.040  MessyHair  -  Server - Server:25
  21:02:06.040   ▶ {...}  -  Server
  21:02:06.040  VarietyShades02  -  Server - Server:25
  21:02:06.040   ▶ {...}  -  Server