TextChatService.OnIncomingMessage, only one function working

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I would like to be able to change the tag infront of the name and the color too.

  2. What is the issue? Include screenshots / videos if possible!
    The upper function doesn’t start at all. Idk how to fuse them to make them both work.

local TextChatService = game:GetService("TextChatService")
local Players = game:GetService("Players") 
local player = script.Parent.Parent
player.CharacterAdded:Wait()
local Tag = game.Workspace.Date.Giocatori:FindFirstChild("="..player.Name)
local Color

TextChatService.OnIncomingMessage = function(message: TextChatMessage)
	local properties = Instance.new("TextChatMessageProperties")

	if message.TextSource then
		local player = Players:GetPlayerByUserId(message.TextSource.UserId)
		if Tag:GetAttribute("Intro") == false then
			properties.PrefixText = "<font color='#FFFFFF'>[Noob]</font> " .. message.PrefixText
		end
	end

	return properties
end

TextChatService.OnIncomingMessage = function(textChatMessage: TextChatMessage)
	local properties = Instance.new("TextChatMessageProperties")
	Color = Tag:GetAttribute("Colore")
	local textSource = textChatMessage.TextSource
	if textSource then
		properties.PrefixText = string.format("<font color='#%s'>%s</font>", Color:ToHex(), textChatMessage.PrefixText)
	end

	return properties
end
  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    tried searching around, found nothing

You are declaring a new function, which is overwriting the first one. Delete one of them and check the userid just like on the first one.

Now the tag and the right color is visible. But the player name not anymore.
If I add the check to the useriD it gives me error.

local TextChatService = game:GetService("TextChatService")
local Players = game:GetService("Players") 
local player = script.Parent.Parent
player.CharacterAdded:Wait()
local Tag = game.Workspace.Date.Giocatori:FindFirstChild("="..player.Name)
local Color

TextChatService.OnIncomingMessage = function(textChatMessage: TextChatMessage, message: TextChatMessage)
	local properties = Instance.new("TextChatMessageProperties")
	
	Color = Tag:GetAttribute("Colore")
	
	local textSource = textChatMessage.TextSource
	
	if textSource then
		if Tag:GetAttribute("Intro") == false then
			properties.PrefixText = string.format("<font color='#%s'>[Noob]</font>", Color:ToHex(), textChatMessage.PrefixText)
		else
			properties.PrefixText = string.format("<font color='#%s'>%s</font>", Color:ToHex(), textChatMessage.PrefixText)
		end
	end

	return properties
end
1 Like

You have forgotten to place your second placeholder %s in this line:

properties.PrefixText = string.format("<font color='#%s'>[Noob]</font>", Color:ToHex(), textChatMessage.PrefixText)

It should probably read something like:

properties.PrefixText = string.format("<font color='#%s'>[Noob] %s</font>", Color:ToHex(), textChatMessage.PrefixText)
1 Like

thank you a lot @be_nj . Didn’t see it

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.