Why does this not print sometimes?

game.Players.PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(function()
print'test'
end)
end)

Every once and a while this script won’t even run… Why is this?

1 Like

that doesn’t matter… why would that change anything?

1 Like

How often does it not print?
Can you get it to stop printing after a certain amount of characters are added?

1 Like

It’s very rare so it’s hard to test. All I’m doing is pressing play constantly in test mode, sometimes it just doesn’t print at all.

1 Like

Is it a local script?, Certain it is. If it is change is to a ServerScript

1 Like

Also its:

print("test")

-- not

print "test"
2 Likes

I got this to work

local Players = game:GetService("Players")
local function onCharacterAdded(character)
    print("test")
end
local function onPlayerAdded(player)
    print("test1")
	player.CharacterAdded:Connect(onCharacterAdded)
end
Players.PlayerAdded:Connect(onPlayerAdded)

1 Like
print'test'

This works completely fine, if you can read what i’m saying is that sometimes it doesn’t print. No, it’s not a LocalScript it’s a ServerScript.

1 Like

Where did you place this script anyways? By any chance, not in ServerScriptService?

1 Like

It’s in serverscriptservice for me, I usually put all my playeradded functions in there.

1 Like

It should be working, but something else is hindering it. When does it not fire? Does it fire consistently when you reset the character?

1 Like

Yes, I think the only times when it doesn’t load is whenever I first join.

1 Like

Sometimes the PlayerAdded event fires before the script connects the signal. That’s why you should loop through existing players as well.

1 Like

What? I’m confused of what you mean by that. Could you maybe explain what you mean?

1 Like

It is simply because CharacterAdded event sometimes doesn’t fire right after PlayerAdded, which is quite odd in my opinion. Try to look for the player’s character first by Player.Character, otherwise fall back to Player.CharacterAdded event.

1 Like

That’s what I was thinking maybe the character already exists, so I added a print where it checks if Player.Character exists then prints it when the players added to see if it exists + doesn’t fire. I’ll get back to you if it doesn’t print though.

1 Like

Make sure the player’s character doesn’t already exist:

game.Players.PlayerAdded:Connect(function(Player)
    if not Player.Character then Player.CharacterAdded:Wait() end
    print("test")
end)
2 Likes

That doesn’t really answer why CharacterAdded doesn’t run occasionally.

Yeah cause its already been answered

game.Players.PlayerAdded:Connect(function(Player)
	local Character = Player.Character or Player.CharacterAdded
	print("Character Exists")
	Player.CharacterAdded:Connect(function()
		print("Character Spawned")
	end)
end)