CharacterAdded event not connecting

So I have a server script inside ServerScriptService and inside of it I’m cloning a BillboardGui to the player. The problem I’ve having is with some inconsistencies regarding the characteradded event as sometimes it’ll work and sometimes it won’t which causes the dependencies for that billboard to not work.

I’ve googled it and saw a lot of post about a similiar issue and a lot of them refer to players loading in before the event can fire or something like that so I’ve tried different solution of custom loading the player when they join and whatever else I could find but nothing seems to work.

Here’s the full script incase something else is interfering that I’m not seeing. (Inserting character doesn’t print)

--[ SERVICES ]--

local RS = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local Player = Players.LocalPlayer

--[ LOCALS ]--

local PlayerTag = RS:WaitForChild("Misc").PlayerTag

--[ FUNCTIONS ]--

Players.PlayerAdded:Connect(function(Player)
	local PlrStats = Player:WaitForChild("Stats")
	local Time = PlrStats.PlayerTime

	Player.CharacterAdded:Connect(function(Character) -- < Here
		print('Getting Character')
		local Humanoid = Character:WaitForChild("Humanoid")
		local CloneGui = PlayerTag:Clone()
		
		repeat CloneGui.Parent = Character.HumanoidRootPart print('Loading Data')
		until Character.HumanoidRootPart:FindFirstChildWhichIsA("BillboardGui")
		
		local Died = false
		
    	CloneGui.Timer.Text = Time.Value

		Humanoid.Died:Connect(function()
			Time.Value = 0
			Died = true
		end)

		Time.Changed:Connect(function()			
			PlayerTag.Timer.Text = Time.Value
		end)
		
		while task.wait(1) do
			if Died then
				CloneGui.Timer.Text = 0	
				break 
			end
			
			if not Character:FindFirstChildWhichIsA("ForceField") then
				Time.Value += 1
				CloneGui.Timer.Text = Time.Value
			end
			
		end	
	end)
end)

Thanks ahead of time!

Try this.

--[ SERVICES ]--

local RS = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")

--[ LOCALS ]--

local PlayerTag = RS:WaitForChild("Misc").PlayerTag

--[ FUNCTIONS ]--

Players.PlayerAdded:Connect(function(Player)
	local PlrStats = Player:WaitForChild("Stats")
	local Time = PlrStats.PlayerTime

	Player.CharacterAdded:Connect(function(Character) -- < Here
		print('Getting Character')
		local Humanoid = Character:WaitForChild("Humanoid")
		local CloneGui = PlayerTag:Clone()

		repeat CloneGui.Parent = Character.HumanoidRootPart print('Loading Data')
		until Character.HumanoidRootPart:FindFirstChildWhichIsA("BillboardGui")

		local Died = false

		CloneGui.Timer.Text = Time.Value

		Humanoid.Died:Connect(function()
			Time.Value = 0
			Died = true
		end)

		Time.Changed:Connect(function()			
			PlayerTag.Timer.Text = Time.Value
		end)

		while task.wait(1) do
			if Died then
				CloneGui.Timer.Text = 0	
				break 
			end

			if not Character:FindFirstChildWhichIsA("ForceField") then
				Time.Value += 1
				CloneGui.Timer.Text = Time.Value
			end

		end	
	end)
end)

Out of test playing 10 times, it failed to load the character 3 times.
Maybe it’s just a Studio thing and it’ll just never happen in game?

Maybe try replacing Player.CharacterAdded:Connect(function(Character) with this.

--[ SERVICES ]--

local RS = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")

--[ LOCALS ]--

local PlayerTag = RS:WaitForChild("Misc").PlayerTag

--[ FUNCTIONS ]--

Players.PlayerAdded:Connect(function(Player)
	local PlrStats = Player:WaitForChild("Stats")
	local Time = PlrStats.PlayerTime
	
	
	local Character = Player.Character or Player.CharacterAdded:Wait()
	print('Getting Character')
	local Humanoid = Character:WaitForChild("Humanoid")
	local CloneGui = PlayerTag:Clone()

	repeat CloneGui.Parent = Character.HumanoidRootPart print('Loading Data')
	until Character.HumanoidRootPart:FindFirstChildWhichIsA("BillboardGui")

	local Died = false

	CloneGui.Timer.Text = Time.Value

	Humanoid.Died:Connect(function()
		Time.Value = 0
		Died = true
	end)

	Time.Changed:Connect(function()			
		PlayerTag.Timer.Text = Time.Value
	end)

	while task.wait(1) do
		if Died then
			CloneGui.Timer.Text = 0	
			break 
		end
		
		if not Character:FindFirstChildWhichIsA("ForceField") then
			Time.Value += 1
			CloneGui.Timer.Text = Time.Value
		end
	end
end)

That’s common problem when loading the character for the first time, most of the time this is how I counter the issue:

local function CharacterAdded(character)
	print(Player, character)
end

CharacterAdded(Player.Character or Player.CharacterAdded:Wait()) --may want to pcall, if it errors the first time it will break the entire thing
Player.CharacterAdded:Connect(CharacterAdded)

That is a very good way of fixing it also!

Is this a server script in SSS?

You should be able to handle what you are trying to do from the server, he is giving an example of how you could wait for the character to load so that you don’t fail to load the character.