I Need Help With A Toggable Chat Tag Script!

So I want to make a chat tag script for me (vk0gj), and with a click of a button it turns off. I cant seem to find a way to do it! Can someone please provide me with something to help me? I’ve tried every chat-tag script out there and tried to make it turn off when I clicked a button. I even tried remote events! Please help me.

4 Likes

A UI Button?

TextChatService or Legacy?

Legacy Chat is getting removed but just want to make sure

1 Like

yeah legacy for now, and yes a ui button

1 Like

You should really start to switch now. It’s getting removed soon.

Make a RemoteEvent inside of ReplicatedStorage. Call it “ToggleChatTag”.

Make a ScreenGui in StarterGui. Then, add a TextButton or ImageButton inside of it.
After that, add a LocalScript into the button.

Insert this code into it.

local RemoteEvent = game:GetService("ReplicatedStorage").ToggleChatTag
local toggled = false

script.Parent.MouseButton1Click:Connect(function()
	toggled = not toggled
	RemoteEvent:FireServer("BIG FAN", toggled) -- replace "BIG FAN" with your tag text
end)

This is the client part done. It sends an event over whenever the player wants the chat tag.

Now, we need to make the server-side give the player the tag.
We also need to verify if it is a tag that is toggleable.

To do this, add a normal Script into ServerScriptService.
Here is the code that will make it work:

local ChatService = require(game:GetService("ServerScriptService"):WaitForChild("ChatServiceRunner").ChatService)
local RemoteEvent = game:GetService("ReplicatedStorage").ToggleChatTag

local ToggleableTags = {
	"BIG FAN"
}

local function CheckTableEquality(t1,t2)
	for i,v in next, t1 do if t2[i]~=v then return false end end
	for i,v in next, t2 do if t1[i]~=v then return false end end
	return true
end

RemoteEvent.OnServerEvent:Connect(function(plr, name, enabled)
	if table.find(ToggleableTags, name) then
		local speaker = ChatService:GetSpeaker(plr.Name)
		
		local tags = speaker.ExtraData.Tags
		local tag = {TagText = name, TagColor = Color3.fromRGB(255, 255, 255)}
		
		if enabled then
			table.insert(tags, tag)
			speaker:SetExtraData("Tags", tags)
		else
			for i,v in pairs(tags) do
				if CheckTableEquality(v, tag) == true then
					table.remove(tags, i)
					break
				end
			end
			speaker:SetExtraData("Tags", tags)
		end
	end
end)

The CheckTableEquality function was taken from here.

The ChatService is what lets you add chat tags on Legacy Chat.
Whenever a player fires the remote event, we check if the tag is toggleable. This is to stop exploiters from adding their own tags.

If it is found, we get the player’s old tags.
Then, if we want it to be on, we add the tag onto that list and apply it.
If we want it to be off, we remove it from the list and apply the list.

This is very different in TextChatService.
This does not support colours, although I can help you add that as it is quite easy to do.

1 Like

so this does work, but i eanted to know, when i try to make server chattags for the new chat verision. Yet, its local so only I can see the chattags. Do you think they will come out with a server verision of the chattags?

ALSO I want only me to have chattags. should I make an if statment?

If you want to use the new TextChatService, you can check the bottom of the TextChatService documentation page, where it goes over replicating the LegacyChat’s tag system

Otherwise, you can use the TextChatService.OnIncomingMessage callback to return a TextChatMessageProperties to change the PrefixText, the text displayed before the message


With legacy chat, you can also use Chat:RegisterChatCallback() to apply tags, here is some code that adds tags, that I used to test my port of LegacyChat

local Chat = require(game.ReplicatedStorage.Chat)

Chat:RegisterChatCallback("OnServerReceivingMessage", function(messageObj) 
	messageObj.ExtraData.NameColor = Color3.new(1, 0.6, 0.109804) -- Changes the color of the player's name
	messageObj.ExtraData.Tags = {
		{
			TagText = "VIP",
			TagColor = Color3.new(1, 215/255, 0)
		},
		{
			TagText = "Alpha Tester",
			TagColor = Color3.new(205/255, 0, 0)
		}
	}
	return messageObj
end)

messageObj contains information about the message, including who sent it and a bunch of other stuff


So you can use MessageObj.SpeakerUserId == [Your user id] to check if the message was sent by you

1 Like

ik that but if you DO try and run it on a server script, it usually just gives an error, but thanks!

Yeah you have to run it on every client. You can have a BoolValue to enabled disable it from the server, and its state will replicate to every client, and every client applies the tag

1 Like

oh ok, before i close this, could you help me with the line of code

local ChatService = require(game:GetService(“ServerScriptService”):WaitForChild(“ChatServiceRunner”).ChatService)
local RemoteEvent = game:GetService(“ReplicatedStorage”).ToggleChatTag

local ToggleableTags = {
“BIG FAN”
}

local function CheckTableEquality(t1,t2)
for i,v in next, t1 do if t2[i]~=v then return false end end
for i,v in next, t2 do if t1[i]~=v then return false end end
return true
end

RemoteEvent.OnServerEvent:Connect(function(plr, name, enabled)
if table.find(ToggleableTags, name) then
local speaker = ChatService:GetSpeaker(plr.Name)

	local tags = speaker.ExtraData.Tags
	local tag = {TagText = name, TagColor = Color3.fromRGB(255, 255, 255)}
	
	if enabled then
		table.insert(tags, tag)
		speaker:SetExtraData("Tags", tags)
	else
		for i,v in pairs(tags) do
			if CheckTableEquality(v, tag) == true then
				table.remove(tags, i)
				break
			end
		end
		speaker:SetExtraData("Tags", tags)
	end
end

end)

i want it to only have me be able to have chat tags, my user is vk0gj, and I tried everything. Nothing seems to work. This also is legacy…

What is the client side script? You should also add a line right after RemoteEvent.OnServerEvent:Connect(function(plr, name, enabled), to make sure only you can use the remote, something like
if plr.UserId ~= 541381576 then return end -- 541381576 is your UserId

local ChatService = require(game:GetService("ServerScriptService"):WaitForChild("ChatServiceRunner").ChatService)
local RemoteEvent = game:GetService("ReplicatedStorage").ToggleChatTag

local ToggleableTags = {
	"BIG FAN"
}

local function CheckTableEquality(t1,t2)
	for i,v in next, t1 do if t2[i]~=v then return false end end
	for i,v in next, t2 do if t1[i]~=v then return false end end
	return true
end

RemoteEvent.OnServerEvent:Connect(function(plr, name, enabled)
	if plr.UserId == 541381576 and table.find(ToggleableTags, name) then -- only allows you to use it.
		local speaker = ChatService:GetSpeaker(plr.Name)
		
		local tags = speaker.ExtraData.Tags
		local tag = {TagText = name, TagColor = Color3.fromRGB(255, 255, 255)}
		
		if enabled then
			table.insert(tags, tag)
			speaker:SetExtraData("Tags", tags)
		else
			for i,v in pairs(tags) do
				if CheckTableEquality(v, tag) == true then
					table.remove(tags, i)
					break
				end
			end
			speaker:SetExtraData("Tags", tags)
		end
	end
end)

Does this work? (Legacy Chat)


@vk0gj
Are you sure this is the solution you are satisfied with? It will not work with the new chat.

2 Likes

WAIT i need 1 more thing, i want there to be multiple for specific people, like Player 1 has Owner Chat Tag, while Player 2 has Developer Chat Tag. EX.

OWNER [vk0gj]: hi Player 1.
DEVELOPER [Player1]: Hi vk0gj!

Could you give more details?

How many tags per person? One?
Just one person, or more?

With one button? Or multiple that don’t work if you don’t have permissions?

just 2 and ill add one. just do like 2 tags for multiple people. it doesn’t matter ill fix the usernames and stuff. I really don’t know how to explain it better, sorry. Also just 1 per-person pls and 1 button

1 Like

Do you mean this?

Player 1:
image

Player 2:
image

yes, but for different people. Like JakeMan123 Has Developer
but vk0gj has Owner.

Alrighty!

All comments should be removed inside of the script. They are there so you can see what changed easily.

To do this, we must modify the server Script, not the LocalScript.

What was changed

We can remove the ToggleableTags table as we will no longer use it.
Instead, we will use the plrTags table to specify specific tags for specific players.

We can remove the owner check statement we made previously.
We can make the tag of the player’s UserId in the table a variable.
We then check if it even exists.


Final Code:

local ChatService = require(game:GetService("ServerScriptService"):WaitForChild("ChatServiceRunner").ChatService)
local RemoteEvent = game:GetService("ReplicatedStorage").ToggleChatTag

--local ToggleableTags = {
--	"BIG FAN"
--}

local plrTags = {
	[541381576] = {
		TagText = "OWNER",
		TagColor = Color3.fromRGB(48, 114, 255)
	},
	[1] = {
		TagText = "ROBLOX",
		TagColor = Color3.fromRGB(255, 255, 255)
	}
}

local function CheckTableEquality(t1,t2)
	for i,v in next, t1 do if t2[i]~=v then return false end end
	for i,v in next, t2 do if t1[i]~=v then return false end end
	return true
end

RemoteEvent.OnServerEvent:Connect(function(plr, name, enabled)
	--if plr.UserId == 541381576 and table.find(ToggleableTags, name) then

	local tag = plrTags[plr.UserId]
	if not tag then return end

	local speaker = ChatService:GetSpeaker(plr.Name)
	local tags = speaker.ExtraData.Tags

	if enabled then
		table.insert(tags, tag)
		speaker:SetExtraData("Tags", tags)
	else
		for i,v in pairs(tags) do
			if CheckTableEquality(v, tag) == true then
				table.remove(tags, i)
				break
			end
		end
		speaker:SetExtraData("Tags", tags)
	end
	--end
end)

I added Roblox as an example instead of developer because I don’t know any of your developers :skull:
This also supports Colours!


To add a person, just copy and paste one of the example tables e.g

[541381576] = {
		TagText = "OWNER",
		TagColor = Color3.fromRGB(48, 114, 255)
	},

and change the number to their UserId! The rest is for you to customize.


1 Like