:IsA() doesn't work

I don’t know if this is a bug or if I am doing something wrong. But when I run the following code:

for i,v in pairs(game.Players.StrategicPlayZ:GetChildren()) do print(v:IsA("Accessory")) end

It prints “false” 5 times, even though there are many objects in my character, like 10-12, and also a few accessories, but it doesn’t print that too.

It is not looping through all of them.

1 Like

Because you’re iterating through the Player instance’s children. You should be iterating over the character. The Character property of a player references their instance in Workspace that holds their Humanoid, Hats, and equipped Gear, and everything that you would expect the player’s Character to have.

https://developer.roblox.com/en-us/api-reference/property/Player/Character

for i, v in pairs(game.Players.StrategicPlayZ.Character:GetChildren()) do
    print(v:IsA("Accessory"))
end

However I suggest you clean up the code a bit.

local players = game:GetService("Players")

local player = players.StrategicPlayZ
local character = player.Character

local children = character:GetChildren()

for i, child in pairs(children) do
    print(child:IsA("Accessory"))
end
2 Likes

Carrying on with what @EpicMetatableMoment said, you should probably check that the player is fully loaded as well, before you run this code.

3 Likes

Is there a good method for checking wheter the character of a player has fully loaded in or not?

https://developer.roblox.com/en-us/api-reference/function/Player/HasAppearanceLoaded

Is a pretty good way to do just that

Edit: I thought I would add some more context
You probably want to use a repeat loop for this because it checks before it waits,

repeat
wait();
until player:HasAppearanceLoaded();

I should note there is also an event for this, which might be better in this scenario.

https://developer.roblox.com/en-us/api-reference/event/Player/CharacterAppearanceLoaded

1 Like

thank you. :>

30chars?

Right on @EpicMetaTableMoment,

I wasn’t aware of this event.

In this case you could do:
player.CharacterAppearanceLoaded:wait();

1 Like