Chat Tags Combine with a textbutton

I would like to create something that players could get a Chat-tag via Textbutton, I looked up on Devforums, google, Youtube and i found nothing, i tried combing the Chat tag script and added the mousebutton1click but it didnt worked. can someone help me or give me a reference?

2 Likes

Can you explain in more detail what exactly you want to achieve? I dont quite understand your problem!

1 Like

Hello!

From what I understood from your post, it seems like you want players to be able to enable a chat tag via clicking a TextButton.

If you are using a script similiar to this one: x_ontez’s post, then I believe implementing a RemoteEvent to the script should do the thing.

Connect the RemoteEvent to the MouseButton1Click function.

(LocalScript)

local yourButton = -- ROUTE TO YOUR BUTTON HERE
local yourRemoteEvent = -- ROUTE TO YOUR REMOTE EVENT HERE

yourButton.MouseButton1Click:Connect(function()
  yourRemoteEvent:FireServer()
end)

(ServerScript)

local yourRemoteEvent = -- SAME ROUTE TO YOUR REMOTE EVENT HERE
local chatService = require(game.ServerScriptService:WaitForChild("ChatServiceRunner"):WaitForChild("ChatService"))

local tags = {
	[0] = {TagText = "TUTORIAL", TagColor = Color3.fromRGB(255, 0, 0)}, -- The 0 must be changed to the the id of the user you want the tag to have
}

yourRemoteEvent.OnServerEvent:Connect(function(player)
    local speaker = chatService:GetSpeaker(player)
	local player = game.Players[playerName]
	
	if tags[player.UserId] then
		speaker:SetExtraData("Tags",{tags[player.UserId]})
	end
end)

You can split the process into parts to make it easier:

  1. Have a StringValue on the server of CSV(comma separated values) representing each tag a user owns as tag1,tag2,tag3, tagN. If you want to add more functionality like picking tag color as well you can store dictionaries as JSON encoded strings instead in that value(basically an array of dictionaries representing tags, with properties like Text, Color, etc).
  2. Have some sort of UI for requesting said data from the user and passing it through a remote to the server.
  3. Sanitize and validate the data on the server, and set it to their StringValue.
  4. Have something checking when the StringValue changes, every time it changes run a script that JSON decodes the data(or splits it from commas depending on how you stored the data) fetches the tags, and sets them to their Speaker object through the Roblox Chat API(I think the new chat and old chat have different ones, so you need to either make functionality for both or the one your game uses).
  5. If you want the data to be stored, utilize datastores to load and save the data to and from the StringValue of said player to the player data and vice versa.

Indeed, what you’re asking for most likely doesn’t exist in a single dev forum post, however, in situations like this you can try breaking down the problem, which is always the first step for solving it. If I’m not mistaken all the separated steps described above can be found on the dev forum or in other sources, so all you have to do is after making each one based on your game logic, combine them in such a way so they have the functionality you’re asking for.

Thank you, I’ll will check it later

The ID of the Tags what should i put?

That’s up to you, not me. This is just a tutorial example, I don’t know how your chat tag script works.

If you want every player to be able to access the chat tag, then just connect a function for getting all players’ IDs (or the player’s that just joins) to the inside of the yourRemoteEvent.OnServerEvent function.
If you want only players in a group to be able to access it, connect it to a :IsInGroup() function aswell. Same goes for gamepasses, etc.

TL;DR: Setting up the rest of the script is up to you, such as the routes or IDs. I just gave you a blank tutorial example of how you can achieve this feature.

Off-topic note:
This is obviously not the only way of achieving this feature. There can be many more other ways, such as the one @NyrionDev mentioned. It’s also not the best exploting-wise, seen that it is a RemoteEvent which can eventually be accessed by exploiters, which then could give the chat tag to themselves. However, it should work.