How to Create a Custom Chat Tag

Chat Tags are emoji’s or Text that appear next to a player’s username in chat. These tags indicate a variety of things, such as a player’s membership status, participation in events, or even their role within a game. Chat tags are a way for players to show off their achievements and status within the Roblox Game. Overall, chat tags serve as a visual representation of a player’s accomplishments or specific role in roblox game

image

Here is a step-by-step guide to creating a chat tag:
(I assume that you possess basic knowledge such as how to open a game,create scripts,etc)

Step 1: Insert a loaclscript into StarterPlayer > StarterPlayerScripts

Step 2: Open the localScript

Step 3: Just type the code down below. {The provided script is completely editable, and with basic knowledge and understanding, you can modify the tags to your liking.}

local txt = game:GetService("TextChatService")
txt.OnIncomingMessage = function(msg:TextChatMessage)
	local p = Instance.new("TextChatMessageProperties")
	if msg.TextSource then
		p.PrefixText = "<font color='#0000ff'>[Tutorial]</font> "..msg.PrefixText
	end
	return p
end

Explanation :
Specifically, the function creates a new TextChatMessageProperties object, which represents the properties of a chat message, and sets the PrefixText property of the object to a formatted string that includes the name of the player who sent the message and a custom prefix text in blue color. The function then returns the modified TextChatMessageProperties object.

Here’s a breakdown of the code:

  • local txt = game:GetService("TextChatService") is line of code that get important parts of the game
  • txt.OnIncomingMessage = function(msg:TextChatMessage) sets up a function that will be called whenever a new message comes in. It takes one argument, which is a TextChatMessage object that represents the message.
  • local p = Instance.new("TextChatMessageProperties") creates a new object that we’ll use to modify the message’s appearance.
  • if msg.TextSource then checks if the message was sent by a player (as opposed to a system message or something else).
  • p.PrefixText = "<font color='#0000ff'>[Tutorial]</font> "...msg.PrefixText..': ' sets the prefix text for the message to be the blue “Tutorial” tag followed by the player’s name.
  • return p returns the modified message object.

Overall, this code modifies the appearance of chat messages to include a blue “Tutorial” tag before the name of the player who sent the message.

Is this helpful?

  • Yes
  • No

0 voters



Roblox Group: https://www.roblox.com/groups/6290210

image @Typelnt

79 Likes

this help me alot thanks! keep it up!

2 Likes

NP :]

I would appreciate if you liked the post so, it can reach to more peopl.

4 Likes

this is super helpful! could you explain how we can do to add Gamepasses & Groups as well? using this same method

2 Likes

Thank you for your inquiry regarding adding Gamepasses and Groups to the code using a similar method. To achieve this, you can utilize the references provided:

To implement this functionality, you can follow these steps:

  • Access the plr (player) by using msg.TextSource. This variable represents the Player.
  • Utilize the IsInGroup method to determine if the player is a member of a specific group. If the player is in the group, you can modify the prefixText accordingly.
  • Use the UserOwnsGamePassAsync method to check if the player owns a specific gamepass. If the player owns the gamepass, you can again modify the prefixText as needed.

Here’s an example code snippet to help you get started:

-- Check if the player is in a specific group
if plr:IsInGroup(groupId) then
    p.PrefixText = "[Group Member] " .. msg.PrefixText
end

-- Check if the player owns a specific gamepass
if game.MarketplaceService:UserOwnsGamePassAsync(msg.TextSource.UserId, gamepassid) then
    p.PrefixText = "[Gamepass Owner] " .. msg.PrefixText
end

Please ensure you replace groupId with the actual group ID and gamePassId with the appropriate gamepass ID for your specific use case.

I hope this explanation helps you achieve your desired functionality.

4 Likes

For anyone having trouble getting this to work, ensure your chat version is on TextChatService and not LegacyChatService: Click on TextChatService in Explorer → under properties, Data, ChatVersion, and select TextChatService. In March, TextChatService was made the new default, but no older games were updated. I had this issue and it took me a while to find out what was wrong. Thank you, vipgamernoob1, for the tutorial :smile:

5 Likes

This is very helpful. I just also wish that html wasnt complicated with Lua and it was easier.

3 Likes

No problem, I’m glad it helped you! :sweat_smile:

I understand that working with HTML and integrating Lua can sometimes be complex. If you’re looking for simpler alternatives, you might consider exploring other web development frameworks or libraries that provide easier ways to handle dynamic functionality without the need for Lua. Additionally, there are many resources available online, such as tutorials and documentation, that can help simplify the learning process for HTML and Lua integration. Let me know if there’s anything specific you’d like assistance with!

1 Like

im having a trouble, for some reason the only chat that i can see its myself, i cannot see anyones chat
if u need my script its here

local mps = game:GetService("MarketplaceService")
local TextChatService = game:GetService("TextChatService")
local Players = game:GetService("Players")
TextChatService.OnIncomingMessage = function(message: TextChatMessage)
	local properties = Instance.new("TextChatMessageProperties")
	if message.TextSource then
		local plr = Players:GetPlayerByUserId(message.TextSource.UserId)
		if mps:UserOwnsGamePassAsync(plr.UserId,642630716) or plr.VIP.Value == true then 
			properties.PrefixText = "<font color='rgb(255, 255, 0)'>[VIP]</font> " .. message.PrefixText
		end
		if plr.UserId == 448435441 then
		properties.PrefixText = "<font color='rgb(170, 0, 255)'>[Owner]</font> " .. message.PrefixText
		elseif plr.UserId == 719372696 then
			properties.PrefixText = "<font color='rgb(255, 0, 0)'>[Co-Owner]</font> " .. message.PrefixText
		elseif plr:GetRoleInGroup(9803089) == "DJ's" then
			properties.PrefixText = "<font color='rgb(255, 85, 0)'>[DJ]</font> " .. message.PrefixText
		elseif plr.MembershipType == Enum.MembershipType.Premium then
			properties.PrefixText = "<font color='rgb(180, 180, 180)'>[PREMIUM]</font> " .. message.PrefixText
		end
	end
	return properties
end

1 Like

i mean it doesnt gives any error btw so i really dont know whats wrong and i never worked with TextChatService before :crying_cat_face:

I apologize for my delayed response. I have been quite busy recently. I will review your code as soon as possible.

image
Work’s fine?

Upon further inspection of your code in multiplayer mode, it appears that the error ‘MarketPlace:UserOwnsGamePassAsync() can only query local player’ is indeed thrown. Consequently, the code execution halts, preventing the message from being returned and displayed to other players attempting to check the other gamepass.

To address this, it is necessary to implement a server-side handling mechanism.

server

-- Initialize the MarketplaceService
local MarketplaceService = game:GetService("MarketplaceService")
local GamePassID = 12345678910 -- Replace with the actual GamePass ID

-- Connect the PlayerAdded event to handle player joining
game:GetService('Players').PlayerAdded:Connect(function(player)
	-- Create a BoolValue to track whether the player owns the VIP game pass
	local ownVIP = Instance.new("BoolValue", player) -- default value will be false
	ownVIP.Name = "ownVIP"

	-- Check if the player owns the specified GamePassID
	if MarketplaceService:UserOwnsGamePassAsync(player.UserId, GamePassID) then
		ownVIP.Value = true --false to true
	end
end)

client / localplayer

-- Check for VIP ownership and customize the PrefixText accordingly
local vip = player:WaitForChild("ownVIP").Value
if vip then 
	properties.PrefixText = "<font color='rgb(255, 255, 0)'>[VIP]</font> " .. message.PrefixText
elseif player.UserId == 448435441 then
	properties.PrefixText = "<font color='rgb(170, 0, 255)'>[Owner]</font> " .. message.PrefixText
end
1 Like

I don’t know if I explained myself correctly but what I was referring to was that I couldn’t see the other players’ chat and they couldn’t see the other players either.
I figured out how to make it with the Legacy Chat using only a Script but also thanks for you response I red something before that roblox gonna make the LegacyChat deprecated like Filtering Enabled and things like that or something, so I probably check this out more in the future

As previously mentioned, the act of sending a message triggers a function within the LocalScript.

The crux of the matter lies in the script’s attempt to verify gamepass ownership using MarketPlace:UserOwnsGamePassAsync() within the LocalScript. Moreover, this method is inherently tailored to authenticate the gamepass solely for the LocalScript’s user and does not extend to others. Consequently, attempting to check other players’ gamepasses from your LocalScript results in an error.

To accurately ascertain whether others possess the gamepass, it is imperative to implement this method on the server side.

In effect, when you send a message, it proceeds without error for yourself, enabling the message to be displayed. Conversely, an error occurs for others, hindering further execution and impeding the interception of their chat.

I had the same issue has them, and i didnt know what was going on, so i switched to the legacy chat, several months later–now that i understand why i had the same error as they had, i can fix it, thank you! :slightly_smiling_face:

Just realised a problem with this, its not very “exploiter-protected”, im trying to figure out a way to prevent an exploiter from locating that boolvalue and changing its propertie to true, since the “detecting if boolvalue is true logic” is on the client and they dont own the gamepass it will show that tag, any ideas?

1 Like

I believe there might be a misunderstanding regarding how exploitation functions.

Exploiters typically lack direct access to the server or other clients. The primary concept of exploitation involves altering elements on the client side, which subsequently replicate those changes to the server. For instance, when a boolean value is replicated from the client, its value remains consistent for everyone. If an exploiter modifies their client-side “value” to true, this alteration only impacts the exploiter. In essence, only the exploiter can perceive this change within their own context, rendering it unaffectable to others and thereby ensuring its safety.

Have you observed the teleportation exploit? Its functionality hinges on manipulating the replication from the client to the server. Essentially, the server replicates the client’s position to ensure smoother movement for the player. If the position is altered from the client to a different location, the server naturally replicates this change. Consequently, the player is relocated on the server, making the teleportation visible to all other players.

ok thank you, ill keep this in mind!