OnIncomingMessage only fires once, no errors

So, I’m currently attempted to add Chat tags to my game, and I’m having a small problem where OnIncomingMessage only fires for the very first message (that being the “roblox translates all messages” message), and entirely stops working after.

I haven’t written anything wrong, have I?

function setTag(message, displayName, tag)
	local tagData = rankList.Developer
	message.PrefixText = string.format("[<font color='rgb(%d,%d,%d)'>%s</font>] %s",
		tagData.TagColor.R * 255,
		tagData.TagColor.G * 255,
		tagData.TagColor.B * 255,
		tagData.TagText,
		displayName
	)
end

TextChatService.OnIncomingMessage = function(message)
	local properties = Instance.new("TextChatMessageProperties")
	--// Below line purely for testing if the tags even work, they do.
	setTag(properties, "SERVER", "Developer")
	
	if message.TextSource then
		
		local player = Players:GetPlayerByUserId(message.TextSource.UserId)
		local rankInGroup = player:GetRankInGroup(11598588)
		if rankInGroup >= 254 then
			setTag(properties, player.DisplayName, "Developer")
		elseif rankInGroup == 253 then
			setTag(properties, player.DisplayName, "Admin")
		elseif rankInGroup == 252 then
			setTag(properties, player.DisplayName, "Tester")
		end
	end
	
	return properties
end

image

Well, turns out my situation was very specific.

The script had to be located in either StarterPlayerScripts or ReplicatedFirst (I opted for ReplicatedFirst) as the characters don’t load until the player clicks a button, and as such starterGui also doesn’t load.

The fix was either a 3+ second wait in the script before the function was called, or for me to tie it into my games loading and only activating itself after loading finished, which despite loading being less than 3 seconds (closer to 0.7 seconds) it still works.
Why? I don’t know. Thank you roblox, we all love you and your jankiness.

And I’ll be keeping this post up incase anyone else runs into the same issue later down the line, never know when something like this will be useful to someone.