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.
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.
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.
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.