Create chat tags with the new TextChatService?

I want to create chat tags in my game using the new TextChatService.

I’m not sure how I would do this.

Thanks for any help.

I have looked on the dev forum and only found a gamepass-locked one, but i don’t want a gamepass locked one.

2 Likes

Hello,

When Roblox announced this feature they included examples of how to do it!

Heres the devforum post. I believe you are looking for the VIP Demo one

6 Likes

I’m trying to give players chat tags based on their username

So for example, if my username is AdSomnum, I’ll get an Owner chat tag

Just add

if player.Name == "AdSomnum" then
--Your code
end
1 Like

would I do this in a local script in starterplayerscripts?

Yes, or it could go in starter GUI or whatever but I think StarterPlayerScripts would be more realistic.

alright, thank you for your help!

You are absolutely welcome!

Have a great day.

1 Like

I did this

local TextChatService = game:GetService("TextChatService")
local Player = game:GetService("Players").LocalPlayer

TextChatService.OnIncomingMessage:Connect(function(message: TextChatMessage)
	local props = Instance.new("TextChatMessageProperties")
	if Player.Name == "AdSomnum" then
		props.PrefixText = "<font color='#000001'>[Owner]</font> " .. message.PrefixText
	end
end)

in a local script in starterplayerscripts

and it didn’t work

With the part that says prefix text, I don’t think you completed that line fully.

Go back and re read what the full line said.

props.PrefixText = "<font color='#F5CD30'>[VIP]</font> " .. message.PrefixText

that is the line in the VIP script from the forum link

props.PrefixText = "<font color='#000001'>[Owner]</font> " .. message.PrefixText

that is the line in my script

it’s completed i just changed the colour and tag

I’m pretty sure it ends with more of the HTML looking stuff what message.prefixtext.

I would try to be more help but I’m on my phone right now.

i made this (it gives a tag called OG to players who have a badge)

local ogs = {}

game.Players.PlayerAdded:Connect(function(plr)
	local has = game:GetService("BadgeService"):UserHasBadgeAsync(plr.UserId,2126845717)
	if has then
		if not table.find(ogs,plr.UserId) then
			table.insert(ogs,plr.UserId)
		end
	end
end)

game.Players.PlayerRemoving:Connect(function(plr)
	pcall(function()
		table.remove(ogs,plr.UserId,table.find(ogs,plr.UserId))
	end)
end)

local TextChatService = game:GetService("TextChatService")

TextChatService.OnIncomingMessage = function(message)
	local fromuser = message.TextSource.UserId
	
	local props = Instance.new("TextChatMessageProperties")
	
	if table.find(ogs,fromuser) then
		props.PrefixText = "<font color='#FFFF00'>[OG]</font> " .. message.PrefixText
	end
	
	return props
end

for i,plr in ipairs(game.Players:GetPlayers()) do
	pcall(function()
	local has = game:GetService("BadgeService"):UserHasBadgeAsync(plr.UserId,2126845717)
	if has then
		if not table.find(ogs,plr.UserId) then
			table.insert(ogs,plr.UserId)
		end
		end
	end)
end


2 Likes

Hello. You forgot to return the TextChatMessageProperties

local TextChatService = game:GetService("TextChatService")
local Player = game:GetService("Players").LocalPlayer

TextChatService.OnIncomingMessage:Connect(function(message: TextChatMessage)
	local props = Instance.new("TextChatMessageProperties")
	if Player.Name == "AdSomnum" then
		props.PrefixText = "<font color='#000001'>[Owner]</font> " .. message.PrefixText
		return props
	end
end)
2 Likes

TextChatService - Chat Tags

    local dev = {}
    local specificPlayer = "username" -- Change to your username

    game.Players.PlayerAdded:Connect(function(plr)
	if plr.Name == specificPlayer then
		table.insert(dev, plr.UserId)
	end
end)

game.Players.PlayerRemoving:Connect(function(plr)
	for i, id in ipairs(dev) do
		if id == plr.UserId then
			table.remove(dev, i)
			break
		end
	end
         end)

local TextChatService = game:GetService("TextChatService")

    TextChatService.OnIncomingMessage = function(message)
	local fromUser = message.TextSource.UserId

	local props = Instance.new("TextChatMessageProperties")

	if table.find(dev, fromUser) then
		props.PrefixText = "[Developer]" .. message.PrefixText
	end

	return props
end

for _, plr in ipairs(game.Players:GetPlayers()) do
	if plr.Name == specificPlayer then
		table.insert(dev, plr.UserId)
	end
end
1 Like

It is not advised to use your username for stuff like this, as you basically won’t be recognized by the script anymore. Use UserId instead! (i apologize for the necro…)

1 Like

don’t mind if i do… ctrl+c, ctrl+v, your code is now my property

Hi @AdSomnum i see that you have a problem, anyways try this out:

local TextChatService = game:GetService("TextChatService")
local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer

TextChatService.OnIncomingMessage = function(msg: TextChatMessage)
	local prop = Instance.new("TextChatMessageProperties")

	if msg.TextSource then
		local plr = Players:GetPlayerByUserId(msg.TextSource.UserId)

		if plr then
			if plr.Name == "AdSomnum" then
				prop.PrefixText = "<font color='#000001'>[Owner]</font> " .. plr.Name .. ": "
			else
				prop.PrefixText = plr.Name .. ": "
			end
		end
	end

	return prop
end

Important

  • with = function(stringParameter: TextChatService) ← the service you want the string to parent with? Is use to say that you want the TextChatService.OnIncommingMessage be a function. The OnIncommingMessage is a function within tje Chat that allowed you to get messages for it as we do in the code.
  • we get the player by its userId while checking the MessageId of the Messafe the Player sends: local plr = Players:GetPlayerByUserId(msg.TextSource.UserId) at the end we will put the scope where the code should find the userId to the MessageId of it so the player gets target.
  • after all that we will check if the player was found by typing in: if plr then meaning when plr that we have set with GetPlayerByUserId was or has been found then do if plr.Name == "YOUR_NAME" then prop.PrefixText = "[Owner] " .. plr.Name .. ": " else prop.PrefixText = plr.Name .. ": " end

Anyways it should work?