CharacterAdded doesn't work

Why doesn’t player.CharacterAdded work? There’s 0 errors in the output for it, and I’ve tried it in both studio and the roblox client. Here’s the code if you’re wondering.

Players.PlayerAdded:Connect(function(player) 
	local leaderstats = Instance.new("Folder", player)
	leaderstats.Name = "leaderstats"
	LoadData(player)
	player.CharacterAdded:Connect(function(character)
		
		character.HumanoidRootPart.Position = workspace.Checkpoints["Checkpoint" .. player.leaderstats.Stages.Value].Position + Vector3.new(0,1,0)
		print("move")
	end)
	print("Hello")
end)
1 Like

Try adding a wait() before you move the root part

2 Likes

If you’re teleporting the player on character added always add a wait() before the teleport script.

1 Like

Thanks, could I know why it works this way though?

It doesn’t work this way cause its trying to teleport the player as soon as he spawns, it happened to me before and that was the only fix, its not because of you.

1 Like

Ok it doesn’t work again, I didn’t remove the wait(), it’s just not teleporting me.

Sorry for making this more complicated but this isn’t a good solution due to if the server lagging to some extent this wait() won’t be enough to wait for the character instance to load resulting in failure especially if this runs when a server was just created and a player joined. A more practical way to solving this would to use :WaitForChild() instead.

Another cause of the issue may be that previous code above is yielding the event also resulting it to not run.

Using WaitForChild just gives an infinite yield for me

Try this:

game.Workspace:WaitForChild(Player.Name).HumanoidRootPart.Position = ...

I can’t explain it 100% accurately, but my character just strangely glitches out and is invisible.

Must be some other issue within your code that is causing that.

I didn’t do anything that changes the character though.

Nevermind, it works, and you don’t have to worry about respawning, as I teleport the character instead of killing them, Thanks.

Ok sorry for bothering you, but the glitch happened again. Do you mind if I send you my game link to see for yourself?

Change the CFrame instead of the position.

It’s almost as if the CharacterAdded event doesn’t fire at all. I think I could possibly be because I’m calling a function that uses GetAsync() which is a yielding function

Adding on to this I finally figured it out, the issue was that the GetAsync() function in my data loading function was hindering CharacterAdded because it was called BEFORE CharacterAdded. This is because it’s a yielding call. In order to fix this, you can create the Stages Variable using WaitForChild() instead of wait()

player.CharacterAdded:Connect(function(character)
local Stages = leaderstats:WaitForChild("Stages") -- this will wait until the data is initalized
character.CFrame = workspace.Checkpoints["Checkpoint" .. Stages.Value].CFrame

end)
LoadData() -- just the function that gets the data that has a GetAsync() function in it.

Made this post just to help anyone who runs into the same issue. Peace.