How would I make chat tags?

I’m trying to make chat tags w/o having to go into the chat modules to keep everything clean and simple, but unfortunately it isn’t working in my favor.

I want to make a chat tag for beta testers who join my game, and creators, devs, mods, etc.
The tag should look something like [:loudspeaker:MOD][wayIxn]: Hello world! (I honestly dont care about the emoji.)
The code I currently have does not however, work. It’s in a server script:

local Players = game:GetService("Players")

local Storage = game:GetService("ReplicatedStorage")

local ScriptService = game:GetService("ServerScriptService")

local ChatService = 
require(ScriptService:WaitForChild('ChatServiceRunner'):WaitForChild('ChatService'))

game.Players.PlayerAdded:connect(function(player)

if player.Stats.BetaTester.Value == true then

local Speaker

while not Speaker do

Speaker = ChatService:GetSpeaker(tostring(player.Name))

if Speaker then

break

end

wait()

end

print(Speaker)

Speaker:SetExtraData("NameColor", Color3.fromRGB(209, 193, 97))

Speaker:SetExtraData("ChatColor", Color3.fromRGB(178, 248, 229))

Speaker:SetExtraData("Tags", {{TagText = "Beta Tester", TagColor = 
Color3.fromRGB(189, 83, 83)}})

end

end)
16 Likes

Try this:

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

Players.PlayerAdded:connect(function(player)
	local speaker
	while not speaker do
		speaker = ChatService:GetSpeaker(player.Name)
  		wait()
 	end
 	if player.Name == "Rezault" then
  		speaker:SetExtraData("Tags", {{ TagText = "OWNER", TagColor = Color3.fromRGB(4, 175, 236) }})
  		speaker:SetExtraData("NameColor", Color3.fromRGB(85, 170, 0))
		speaker:SetExtraData("ChatColor", Color3.fromRGB(239, 184, 56))
 	end
end)

Change the if player.Name == “Rezault” to whatever you wish, and make it whatever tag and colour you want.

14 Likes

Please explain what you mean by your code not working - tell us about any errors or differences between expected and actual behavior!

This guide should help you out with the Chat API:

@Rezault: it’s probably better to use ChatService.SpeakerAdded to listen for new Speakers rather than PlayerAdded + loop.

6 Likes

You can use ChatService.SpeakerAdded to achieve this as @sircfenner said, it’s a better choice. Hopefully this solves the issue you’re encountering!

local Players = game:GetService('Players')
local ServerScriptService = game:GetService('ServerScriptService')

local ChatService = require(ServerScriptService:WaitForChild('ChatServiceRunner'):WaitForChild('ChatService'))

ChatService.SpeakerAdded:Connect(function(PlayerName)
	local Speaker = ChatService:GetSpeaker(PlayerName)
	if (Players[PlayerName].Stats.BetaTester.Value == true) then
		Speaker:SetExtraData('NameColor', Color3.fromRGB(209, 193, 97))
		Speaker:SetExtraData('ChatColor', Color3.fromRGB(178, 248, 229))
		Speaker:SetExtraData('Tags', {{TagText = 'Beta Tester', TagColor = Color3.fromRGB(189, 83, 83)}})
	end
end)
46 Likes

@xuefei123 actually has a really good tutorial on this, and though it requires a bit more effort, I really like how it is much more organized and easy to use in my opinion. Read more here.

2 Likes

In a thread I made a few weeks ago, I included code that makes adding and changing certain tags easy.

1 Like

Thanks! It works. :slight_smile: Do you know how I could add some type of “Priority” or make a player have more than one tag? Like [Head Developer][SomeTagHere][wayIxn]: Hello world!

You can assign another tag to a player by adding another table to the function where the tag is initially being assigned & I’m glad that my post had solved your issue! :slight_smile:

local Players = game:GetService('Players')
local ServerScriptService = game:GetService('ServerScriptService')

local ChatService = require(ServerScriptService:WaitForChild('ChatServiceRunner'):WaitForChild('ChatService'))

local Administrators = {
	'PlayerName1',
	'PlayerName2'
}

ChatService.SpeakerAdded:Connect(function(PlayerName)
	local Speaker = ChatService:GetSpeaker(PlayerName)
	for i,v in pairs(Administrators) do
		if (Players[PlayerName].Name == Administrators[i]) then
			Speaker:SetExtraData('NameColor', Color3.fromRGB(209, 193, 97))
			Speaker:SetExtraData('ChatColor', Color3.fromRGB(178, 248, 229))
			Speaker:SetExtraData('Tags', {{TagText = 'Head Developer', TagColor = Color3.fromRGB(189, 83, 83)}, {TagText = 'SomeTagHere', TagColor = Color3.fromRGB(189, 83, 83)}})
		end
	end
end)
10 Likes

Thank you very much! :smiley:

1 Like

how would we add on and take away tags? lets say i have a menu and you can select which tag you want. i put on the developer tag, then put on the admin tag. then i want to take off the admin tag. how would i make it take away the tag and add the tag? (in different scripts too)

1 Like

ChatSpeakers have a method called GetExtraData. You can pass Tags as the ExtraData key, then create a loop function that traverses through the table and removes a table where the TagText element is equal to a target value.

local speakerTags = ChatSpeaker:GetExtraData("Tags")

for _, Tag in pairs(speakerTags) do
    if Tag.TagText == "Admin" then
        table.remove(speakerTags, Tag)
    end
end

ChatSpeaker:SetExtraData("Tags", speakerTags)

I don’t believe the last line is necessary if any changes to the table are automatically saved, considering tables are passed by reference. Try first without; if that doesn’t work, throw the SetExtraData statement back into your code.

Alternatively, if you’re just equipping tags and don’t have any other tag code, you could just avoid doing that completely and assign a tag based on your selection.

local function AdaptTag(Text, Color)
    ChatSpeaker:SetExtraData("Tags", {
        {
            TagText = Text,
            TagColor = Color
        }
    })
end
4 Likes

its saying bad argument #2 to ‘remove’ (number expected, got table)

1 Like

i was looking at this script and was trying to remove the ‘‘SomeTagHere’’ tag, and when trying to remove it i messed up the script, is there anyway to remove it without messing it up? (New to scripting)

1 Like

Perhaps you left in the comma after deleting the second tag?

1 Like

Oh yeah, That fixed it, Thank you

2 Likes

Is it possible to give an effect to the chat tags? An example being a recurring rainbow color effect on the players name tag.

2 Likes

Yeah. You can fork the chat modules (or make your own chat) and use some UI gradients to get the desired look!

1 Like

if you got a group, and you want to use chattags, this is a method i use frequently

local plrs = game.Players

local sss = game.ServerScriptService

local groupId = 7628430

local chatService = require(sss:WaitForChild('ChatServiceRunner'):WaitForChild('ChatService'))

local Colours = {

	Founder = Color3.fromRGB(255, 0, 0);

}

chatService.SpeakerAdded:Connect(function(plr)

	local speaker = chatService:GetSpeaker(plr)

	if plrs[plr]:IsInGroup(groupId) then        

		local PlayerRank = plrs[plr]:GetRoleInGroup(groupId)

		speaker:SetExtraData('NameColor', Color3.fromRGB(255, 255, 255))
		speaker:SetExtraData('Tags', {{TagText = PlayerRank, TagColor = Colours[PlayerRank]}})    

	else

		speaker:SetExtraData('NameColor', Color3.fromRGB(255, 255, 255))
		speaker:SetExtraData('Tags', {{TagText = "Guest", TagColor = Color3.fromRGB(255, 255, 127)}})

	end
end)
1 Like

How to have an image as tag???

I don’t think it’s possible because of constraints…