Chat Tag doesn't go to it respective owner

I have a chat tag script but it should only go to 2 people, but it goes to everyone
image

local txt =game:GetService("TextChatService")
local plrs = game:GetService("Players")
local tagOwners = {
	1226013600,
	--1525172626,
	314786909
}

local tags = {
	"Developer"
	
}

local plr = plrs.LocalPlayer
print(plr.UserId)
for _, v in pairs(tagOwners) do
	if plr.UserId == v then
		txt.OnIncomingMessage = function(msg:TextChatMessage)
			local p = Instance.new("TextChatMessageProperties")
			
			if msg.TextSource then
				p.PrefixText = "<font color='#FF0000'>[Developer]</font>".." "..msg.PrefixText
				return p
			end
		end
	end
end

I got this script from community resources on the devForum and added some tweaks so only a select few could get the tag.

By the way, only one dev is in this game, so only I (timed) should get it

The reason this won’t work is because you checked it too early.
You should check if once the message is being sent.
Try this:

local txt = game:GetService("TextChatService")
local plrs = game:GetService("Players")
local tagOwners = {
    1226013600,
    --1525172626,
    314786909
}

local tags = {
    "Developer"
}

local plr = plrs.LocalPlayer
print(plr.UserId)

txt.OnIncomingMessage:Connect(function(msg)
    local p = Instance.new("TextChatMessageProperties")

    if msg.TextSource then
        if table.find(tagOwners, plr.UserId) then
            p.PrefixText = "<font color='#FF0000'>[Developer]</font>".." "..msg.PrefixText
            return p
        end
    end
end)

You want to use ChatService to apply tags rather than the method you’re currently using.

ChatService is added to ServerScriptService when the game runs and it can be referenced by waiting for ChatServiceRunner and then waiting for ChatService.

Example:

local ServerScriptService = game:GetService("ServerScriptService")
local ChatService = require(ServerScriptService:WaitForChild("ChatServiceRunner"):WaitForChild("ChatService"))

ChatService.SpeakerAdded:Connect(function(playerName)
	local Speaker = ChatService:GetSpeaker(playerName)

	-- Set tag text and colour
	Speaker:SetExtraData("Tags", {{TagText = "Developer", TagColor = Color3.fromRGB(255, 0, 0)}})

	-- Set player chat text colour
	Speaker:SetExtraData("ChatColor", Color3.fromRGB(255, 0, 0))
end)
1 Like

They’re using TextChatService, so it won’t work.

It doesn’t work. It still gives the same problem

I believe I see why. Its adding the tag to everyone on the client side if you are that player with the correct UserId. Would I have to make another script from the server side?

Yeah, you’re basically adding the tag to every single message sent if the LocalPlayer is a developer.
If you ask your non-developer friend if they see the tag in chat, they should tell you no.

Here’s a working script:

local textChatService = game:GetService("TextChatService")

local developers = {
	1226013600,
	--1525172626,
	314786909
}

local function onIncomingMessage(message)
    local properties = Instance.new("TextChatMessageProperties")
    
    local source = message.TextSource
    if source then
        if table.find(developers, source.UserId) then
            properties.PrefixText = "<font color='#FF0000'>[Developer]</font> " .. message.PrefixText
        end
    end
    
    return properties
end

textChatService.OnIncomingMessage = onIncomingMessage

This works, thank you so much.

1 Like

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