Chat tags not working

Hi, I have these Chat tags for my game, and when I/Someone else talks in chat, they have the owner tag, How do I fix it?

local IDs = {111991246,337291338}

local CollabID = 1492603266

local ContributorIDs = {551973005}

local CreatorIds = {1631374761}
local GroupID = 32546712

local textChatService = game:GetService("TextChatService")

local player = game.Players.LocalPlayer

textChatService.OnIncomingMessage = function(message: TextChatMessage)

	local properties = Instance.new("TextChatMessageProperties")

	if message.TextSource then
		
		if player:IsInGroup(32546712) then
			properties.PrefixText = "<font color='#ffff00'>[Member]</font> " .. message.PrefixText
		end

		if player.UserId == 111991246 or player.UserId == 337291338 then

			properties.PrefixText = "<font color='#800080'>[Owner ๐Ÿ‘‘]</font> " .. message.PrefixText

		end

		if player.UserId == 551973005 then

			properties.PrefixText = "<font color='#eb4b79'>[Contributer ๐ŸŽจ]</font> " .. message.PrefixText

		end

		if player.UserId == 1631374761 then

			properties.PrefixText = "<font color='#ff0000'>[Creator ๐ŸŽฅ]</font> " .. message.PrefixText

		end

		if player.UserId == 1492603266 then

			properties.PrefixText = "<font color='#4900ff'>[Collaborator ๐Ÿ˜Ž]</font> " .. message.PrefixText

		end
		
	end
	
	return properties

end
2 Likes

Iโ€™m assuming this would be an issue with the or conditional. Iโ€™m not a big fan of or conditionals myself, and Iโ€™d much rather use a table to store the ownerโ€™s UserIds.

You seem to already have the IDs stored as local IDs = {111991246,337291338}, so we can work with that.

Maybe give this a try?

local IDs : {number} = {111991246, 337291338}

-- Inside the .OnIncomingMessage function:
if table.find(IDs, player.UserId) ~= nil then -- This will check to see if the player's UserId is in the IDs table.
	properties.PrefixText = "<font color='#800080'>[Owner ๐Ÿ‘‘]</font> " .. message.PrefixText
end
4 Likes

Iโ€™ll give this a try, thanks!

[character limit]

Hey, something I just noticed with your code is that youโ€™re using LocalPlayer for .OnIncomingMessage, when you should actually be using TextSource. If you use LocalPlayer (or in your case, itโ€™s a variable assigned to local player) itโ€™ll be running a check for every single Player instead of TextSource, who is the player that actually sent the message.

So instead, your code should be looking like this, which may actually be the reason as to why your code wasnโ€™t functioning correctly earlier.

local IDs : {number} = {111991246, 337291338}

-- Inside the .OnIncomingMessage function:
if table.find(IDs, TextSource.UserId) ~= nil then -- This will check to see if the player's UserId is in the IDs table.
	properties.PrefixText = "<font color='#800080'>[Owner ๐Ÿ‘‘]</font> " .. message.PrefixText
end

You should take care to apply this same logic to every single UserId check in this code.

2 Likes

Hey there,

To boot, I would suggest using the return keyword within each if statement you have there. This prevents any possible overriding cases that may occur when you have multiple prefixes like this, and in particular, the group check. I would also order these most-to-least important, like this:

-- Basic sample,
-- the "return" statement stops the rest of the branches from being checked

if player.UserId == 111991246 or player.UserId == 337291338 then
	properties.PrefixText = "<font color='#800080'>[Owner ๐Ÿ‘‘]</font> " .. message.PrefixText
	return properties
end

if player.UserId == 1631374761 then
	properties.PrefixText = "<font color='#ff0000'>[Creator ๐ŸŽฅ]</font> " .. message.PrefixText
	return properties
end

if player.UserId == 551973005 then
	properties.PrefixText = "<font color='#eb4b79'>[Contributer ๐ŸŽจ]</font> " .. message.PrefixText
	return properties
end

if player.UserId == 1492603266 then
	properties.PrefixText = "<font color='#4900ff'>[Collaborator ๐Ÿ˜Ž]</font> " .. message.PrefixText
	return properties
end

if player:IsInGroup(32546712) then
	properties.PrefixText = "<font color='#ffff00'>[Member]</font> " .. message.PrefixText
	return properties
end

(Small edit, I see that youโ€™re doing concatenation here to support multiple prefixes, but I feel this may be unnecessary? Clutters up chat sometimes)
@gelvinware does also give good advice on how to simplify this.

As for the issue, I believe this stems from your use of player. In your code, you mark it at the beginning of your script as the LocalPlayer:

local player = game.Players.LocalPlayer -- ln. 12

Instead, use the TextSource.UserId property to get the proper sender. This would explain why you saw everyone with the owner tag.

3 Likes

Assuming that this is you and you are the owner of the game, then of course everybody will have the owner tag.

To fix this, remove this line and replace the main function with this:

textChatService.OnIncomingMessage = function(message: TextChatMessage)

	local properties = Instance.new("TextChatMessageProperties")

    local player = game.Players:GetPlayerByUserId(message.TextSource.UserId)

    if player then

        if player:IsInGroup(32546712) then
			properties.PrefixText = "<font color='#ffff00'>[Member]</font> " .. message.PrefixText
		end

		if player.UserId == 111991246 or player.UserId == 337291338 then

			properties.PrefixText = "<font color='#800080'>[Owner ๐Ÿ‘‘]</font> " .. message.PrefixText

		end

		if player.UserId == 551973005 then

			properties.PrefixText = "<font color='#eb4b79'>[Contributer ๐ŸŽจ]</font> " .. message.PrefixText

		end

		if player.UserId == 1631374761 then

			properties.PrefixText = "<font color='#ff0000'>[Creator ๐ŸŽฅ]</font> " .. message.PrefixText

		end

		if player.UserId == 1492603266 then

			properties.PrefixText = "<font color='#4900ff'>[Collaborator ๐Ÿ˜Ž]</font> " .. message.PrefixText

		end

    end
	
	return properties

end
2 Likes

I used every method in this forum, so im not sure who actually solved the problem, but iโ€™ll give you the solution for basically mentioning all the problems, thank you all though!

1 Like

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