CharacterAdded not working?

Hi guys,

I am messing around with a character added function, and I cannot seem to get it working.

This is the code, I am just checking for the print to work, and it is on a local script:

local player = game.Players.LocalPlayer
local leaderstats = player:WaitForChild("leaderstats")
local stage = leaderstats.Stage.Value

player.CharacterAdded:Connect(function()
	print("player added")
end)

Similar post below:
CharacterAdded Not Working

I would advise you to use PlayerAdded before CharacterAdded. The character can’t load if the player hasn’t first

game.Players.PlayerAdded:Connect(function(player)
    print("player added")
    player.CharacterAdded:Connect(function(char)
	    print("character added")
    end)
end)
1 Like

It’s in a localscript. If it’s in a localscript playeradded won’t work because the localscript waits for the localplayer to load and then loads so that’s impossible.

https://developer.roblox.com/en-us/api-reference/event/Players/PlayerAdded
It seems like it does.

It works but only when other players join, not the localplayer because the localscript only runs when the player IS added.

1 Like

This solution should work for a Script and not a LocalScript. I don’t think “game.Players.LocalPlayer” works in a Script.

game.Players.PlayerAdded:Connect(function(plr)
        local leaderstats = plr:WaitForChild("leaderstats")
        local stage = leaderstats.Stage.Value
   
        plr.CharacterAdded:Connect(function(char)
                print("character added")

       end)
end)

Why not just put it in StarterCharacterScripts instead?

1 Like

You are running the function after the character is already added, try this instead

local player = game.Players.LocalPlayer
local leaderstats = player:WaitForChild("leaderstats")
local stage = leaderstats.Stage.Value

local function onCharAdded(Char)
	print("player added")
end

player.CharacterAdded:Connect(onCharAdded)
if player.Character then onCharAdded(player.Character) end

To make it simple for yourself, you can just do this:

local Player = game.Players.LocalPlayer
local Character = Player.CharacterAdded:Wait() -- This gets you your character, allowing you to do the stuff down there.

I’ve had this issue before, it wouldn’t allow me to use this on the client so instead, I used my method above ^ Although I just use it to get the character, but my point still stands, which is why I recommend doing

Player.CharacterAdded:Connect(function()

 end)

on the server