CharacterAdded not working at all

Hello!

Simple problem, basically the title. I’ve searched multiple topics to no avail. For some reason, I just cannot get the CharacterAdded event to fire. Here’s a script with the “safety measures” I’ve taken but it still does not fire.

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(chr)
		print('chr') -- not printing ever
		local rank = player:FindFirstChild('Rank')
		if rank then
			local nt = nameTag:Clone()
			nt.Parent = chr:WaitForChild('Head')
			local groupTags = ChatModule.GroupPrefs.GroupTags
			nt.Overhead.Main.TagText.Text = '['..groupTags[rank.Value].TagText..']'
			nt.Overhead.Main.TagText.TextColor3 = groupTags[rank.Value].NameColour
			nt.Overhead.Main.TagText.TextStrokeColor3 = Color3.fromRGB(groupTags[rank.Value].NameColour.R - 50, groupTags[rank.Value].NameColour.G, groupTags[rank.Value].NameColour.B - 50)
		end
		chr:WaitForChild('Humanoid').Died:Connect(function()
			player:LoadCharacter()
		end)
	end)
	player:LoadCharacter() -- doesn't load the character if AutoLoadCharacter is false
end)

First thing to ask, is that in a localscript? Client sided scripts mostly load after Character is Added (StarterGui, StarterPack, StarterCharacterScripts).

You should do that in server side, if this is the case.

If this isn’t the case, check that your script is in ServerScriptService and is not disabled because everything seems fine with the script.

1 Like

No, it’s server sided. Script isn’t disabled.

Make sure the script is in ServerScriptService not ServerStorage or anywhere else

1 Like

Yep, it is in ServerScriptService.

Is that the full script? If not, then I believe something above the Initial connection is blocking the thread or something similar is happening. Can you try placing a print statement outside it & also in the PlayerAdded block most likely.

1 Like

Also is there any wait() or :WaitForChild() before the script? Make sure the PlrAdded one of the first lines

1 Like

I’ve added a print outside of the CharacterAdded event, and inside of the PlayerAdded event and that seems not to print either.

No yielding in the script. .PlayerAdded isn’t working either though. No infinite yield or errors either.

Here’s my full script:

local Players = game:GetService('Players')
local ServerScriptService = game:GetService('ServerScriptService')
local MPS = game:GetService("MarketplaceService")
local ChatService = require(ServerScriptService:WaitForChild('ChatServiceRunner'):WaitForChild('ChatService'))
local ChatModule = require(script.Parent.ChatPrefs)
local RS = game:GetService('ReplicatedStorage')
local nameTag = RS.Assets.Overhead

local Players = ChatModule.PlayerPrefs

local Tags = ChatModule.TagPrefs

game.Players.PlayerAdded:Connect(function(player)
	print('player added')
	player.CharacterAdded:Connect(function(chr)
		print('chr')
		local rank = player:FindFirstChild('Rank')
		if rank then
			local nt = nameTag:Clone()
			nt.Parent = chr:WaitForChild('Head')
			local groupTags = ChatModule.GroupPrefs.GroupTags
			nt.Overhead.Main.TagText.Text = '['..groupTags[rank.Value].TagText..']'
			nt.Overhead.Main.TagText.TextColor3 = groupTags[rank.Value].NameColour
			nt.Overhead.Main.TagText.TextStrokeColor3 = Color3.fromRGB(groupTags[rank.Value].NameColour.R - 50, groupTags[rank.Value].NameColour.G, groupTags[rank.Value].NameColour.B - 50)
		end
		chr:WaitForChild('Humanoid').Died:Connect(function()
			player:LoadCharacter()
		end)
	end)
	player:LoadCharacter()
end)

ChatService.SpeakerAdded:Connect(function(PlayerName) -- this works which is confusing
	local Speaker = ChatService:GetSpeaker(PlayerName)
	--Group Prefs
	for i, v in pairs(ChatModule.GroupPrefs['GroupTags']) do
		if game.Players[PlayerName]:GetRankInGroup(ChatModule.GroupPrefs['GroupID']) == v['GroupPriority'] then
			Speaker:SetExtraData('NameColor', v['NameColour'])
			Speaker:SetExtraData('ChatColor', v['ChatColour'])
			Speaker:SetExtraData('Tags', {{TagText = v['TagText'], TagColor = v['TagColour']}})
			local rank = Instance.new('StringValue', game.Players[PlayerName])
			rank.Name = 'Rank'
			rank.Value = i
			break
		end
	end
end)

Also added game.Players.PlayerAdded:Wait() to no avail.
Also added wait(1) at the top of the script to no avail either.

1 Like

But It seems like this line can be infinite yielding, because it has WaitForChild in it:

local ChatService = require(ServerScriptService:WaitForChild('ChatServiceRunner'):WaitForChild('ChatService'))

Can you recheck your output tab? Everything else actually seems fine.

1 Like

Just checked again, no infinite yield. Also, that script’s a part of Roblox’s core scripts so it probably wouldn’t infinite yield anyway.

Try adding a print above your PlayerAdded block, I just tested it, it seems to be fine and working for me.

1 Like

I did. I’m just gonna put the script in the character so whenever it loads it’ll automatically fire.

I just retried it, and seems like if you don’t require the ChatService module, it connects fine. And also realised, that it has to wait for sometime (about 3 seconds in my case) for the module to load in.

If you asynchronously load it in someway, that shouldn’t be a problem.

1 Like