GetChildren not working after CharacterAdded

I have a CharacterAdded event under a localscript in the StarterPlayerScripts, and it doesn’t work in the way I want it to.

local player= game:GetService("Players").LocalPlayer

player.CharacterAdded:Connect(function(character)
	print(character)
	print(character:GetChildren())
	print(character:GetDescendants())
	print(character:GetFullName())
	for _,v in pairs(character:GetChildren()) do
		print(v)
	end
end)

This is essentially what I have right now, sort of simplified to the basics, and for some reason, it doesn’t get any of the children.

The output does say the correct character, as in Workspace.blaeblaer, though both the descendants and children tables are empty, and iterating through them prints nothing.

I looked at the documentation and it said that it should have the parts that I need loaded:

" Note that the Humanoid and its default body parts (head, torso, and limbs) will exist when this event fires…"

1 Like

Do you need them locally? when I get them on the server side it works just fine.

game.Players.PlayerAdded:Connect(function(plr)
	local player= plr

	player.CharacterAdded:Connect(function(character)
		print(character)
		print(character:GetChildren())
		print(character:GetDescendants())
		print(character:GetFullName())
		for _,v in pairs(character:GetChildren()) do
			print(v)
		end
	end)
end)

I would prefer to access the character locally, though if there are no solutions and I have to, I can switch over to a server side script.

have you tried CharacterAppearanceLoaded instead of CharacterAdded

I think I figured it out, your character loads, but it doesn’t fire the character added event I think it only fires if you respawn. Try this:

local Players = game:GetService("Players")
local player = Players.LocalPlayer

local function printCharacterInfo(character)
	print("Character added:", character)
	print("Children:", character:GetChildren())
	print("Descendants:", character:GetDescendants())
	print("Full Name:", character:GetFullName())
	print("Individual children:")
	for _, v in pairs(character:GetChildren()) do
		print(v)
	end
end

local function onCharacterAdded(character)
	printCharacterInfo(character)
end

player.CharacterAdded:Connect(onCharacterAdded)

if player.Character then
	print("Character already exists.")
	printCharacterInfo(player.Character)
else
	print("Waiting for character to be added.")
end
1 Like

As a temporary fix, you can always fire a RemoteEvent from the server to a player who activates a CharacterAdded event, passing through their Character model in the event.

For some reason, this event doesn’t fire whatsoever, even when I tried respawning.

The event does fire initially when the player connects, as well as when they respawn, though this was what I originally thought to be the problem.

Are you sure? I have it working. Is the script in starter character scripts?

It is parented under StarterPlayerScripts

I just tested it under starterPlayerScripts and It works, Im truly at a loss then.

I guess I might have to run with this for now, since I’m also very confused why this isn’t working. It could potentially be a studio bug, as the CharacterAdded event is supposed to give the model including its baseparts.

Nevermind, it seems to be that this doesn’t work either. I have a server side script that gets PlayersAdded, and then CharacterAdded, then fires a remote event to the player alongside the character.

Printing from the client side script, it says that character is nil, whereas the server side script does function as intended; printing out the character, children and descendants.

Oh, I MIGHT know why this “bug” is happening, maybe because the character isn’t Archivable. Try this code in the LocalScript where you enable the Archivable property locally.

player.CharacterAdded:Connect(function(character)
	character.Archivable = true
	print(character)
	print(character:GetChildren())
	print(character:GetDescendants())
	print(character:GetFullName())
	for _,v in pairs(character:GetChildren()) do
		print(v)
	end
end)

Shouldn’t the default setting be true?

Yep, it’s set to true by default, I forgot :sweat_smile:

Just edited the previous comment to correct that

I tried this, and it is still giving me the same results. Would it work if I tried the Remote Event solution instead?

This entire problem sort of became a thing when I saved the file to Roblox, and published it as a private game. When I was working on it from a local file, it worked, and CharacterAppearanceLoaded also worked, whereas now it doesn’t.

I have found the incredibly dumb solution:

All I have to do is add a task.wait(0.1) line after the CharacterAdded. I found this after remembering that I also have to do something similar to this every time I try to either set something under a character or add something to it from a CharacterAdded event.

I hope there’s an alternative to this, though, as I don’t like using task.wait() inside of code, as I feel like I might need to alter the wait time to compensate for different clients and their devices.

You’re running workspace.SignalBehavior at Enum.SignalBehavior.Default, which as of now is Enum.SignalBehavior.Immediate. Change it to Enum.SignalBehavior.Deferred which will eventually be the engine default for all experiences moving forward.

You can do something similar to this for yield until character loaded;

local runService = game:GetService('RunService')

return function(player: Player): boolean?
    if not player.Character then return false end

    if player:HasAppearanceLoaded() then return true end

    if runService:IsServer() then
        player.CharacterAppearanceLoaded:Wait()
    else
        repeat task.wait() until player:HasAppearanceLoaded()
    end

    return true
end
1 Like