ChatTag n' New Chat problem

I’m working on a title system. But there seems to be a big issue that I currently have.
Player1 Screen that has a Title equipped:
Screenshot 2024-04-26 193658

Player2 Screen that doesn’t have a Title equipped:
Screenshot 2024-04-26 193702

script:

TextChatService.OnIncomingMessage = function(msg:TextChatMessage)
	local props = Instance.new("TextChatMessageProperties")
	if msg.TextSource then
		local plr = game.Players:GetPlayerByUserId(msg.TextSource.UserId)
		local Title = GetData:InvokeServer(plr)["TitleStats"]["Equipped"]
		local Stats = TitleStats[Title]
		
		print(Title)
		
		if Stats then
			props.PrefixText = [[<font color="]]..convert(Stats["Color"].Keypoints[1].Value)..[[">]].."["..Stats["Text"].."]"..[[</font> ]]..msg.PrefixText
		end
	end
	
	return props
end
1 Like

Is the script loaded for both players? I recommend exposing the player titles as attributes so you don’t have to invoke server for each message :smiley:

wdym by load for both players? its in starterplayerscripts

Nothing to worry then! :smiley: Does your server script for getting data happen to look like this:

GetData.OnServerInvoke = function(Player: Player)
	-- Data stuff for Player
end

In your case where you pass in the plr who might not be your local player, you’ll need to adjust it to look like this instead:

GetData.OnServerInvoke = function(SenderPlayer: Player, Player: Player)
	-- Data stuff for Player, not SenderPlayer
end

Personally I’d expose the current Equipped title as an attribute instead of sending that GetData fetch. That would change your message script into this instead:

TextChatService.OnIncomingMessage = function(msg:TextChatMessage)
	local props = Instance.new("TextChatMessageProperties")
	if msg.TextSource then
		local plr = game.Players:GetPlayerByUserId(msg.TextSource.UserId)
		local Title = plr:GetAttribute("EquippedTitle")
		local Stats = TitleStats[Title]
		
		print(Title)
		
		if Stats then
			props.PrefixText = [[<font color="]]..convert(Stats["Color"].Keypoints[1].Value)..[[">]].."["..Stats["Text"].."]"..[[</font> ]]..msg.PrefixText
		end
	end
	
	return props
end

Hope that solves your problem but if it doesn’t let me know :smiley: