Creating Chat Tags

A simple guide to an adaptable Chat Tag System.

by uhTeddy

Author Avatar

Hello, Thanks for reading this tutorial. Before we begin I would liek to say I have open sourced this project and you will be able to copy and paste the link below to use it

https://www.roblox.com/library/4870873471/Chat-Tag-Service

Step One

To start we need to fork the ChatServiceRunner script from the ChatService. In order to do this we will need to play the game and copy ChatServiceRunner from ChatService.

img|80x45

Step Two

Create a Folder and paste that in the folder.

img|37.5x45

Step Three

Let's now create a script to start scripting in inside the folder we created

--// Services
local Players = game:GetService("Players"); -- Allows us to find players later on.

--// modulated Services
local ChatService = require(script.Parent:WaitForChild("ChatServiceRunner"):WaitForChild("ChatService"));

Step Four

Now that we have the services needed, let's create a module in the same folder so we can easily add tags. We will add tags to it later but for now make sure the code looks like this.

return  {

}

Step Five

Now let's require that module in our main script we created in Step 3.

--// Services
local Players = game:GetService("Players"); -- Allows us to find players later on.

--// modulated Services
local ChatService = require(script.Parent:WaitForChild("ChatServiceRunner"):WaitForChild("ChatService"));
local chatTagCritera = require(script.Parent:WaitForChild("ChatTagCriteria")); -- Make sure to change ChatTagCriteria to the name of the module you created in the previous step.

Step Six

Let's finish off the script. Each line will have a comment explaining what it's doing.

--// Services
local Players = game:GetService("Players"); -- Allows us to find players later on.

--// modulated Services
local ChatService = require(script.Parent:WaitForChild("ChatServiceRunner"):WaitForChild("ChatService"));
local chatTagCritera = require(script.Parent:WaitForChild("ChatTagCriteria")); -- Make sure to change ChatTagCriteria to the name of the module you created in the previous step.

--// tag Handler
ChatService.SpeakerAdded:Connect(function(speakerName) -- The event for a player "speaker" being added
    local player = Players:FindFirstChild(speakerName)
 -- Gets the player object from the speaker
    local speaker = ChatService:GetSpeaker(speakerName)
 -- Gets the speaker from the speaker name

    local playerChatTags = {};
 -- Initializes a table to insert the chat tags.
    for index, chatTag in pairs(chatTagCritera) do
-- Iterates through each tag in the module
        local checkCriteria = chatTag["checkCriteria"](player);
 -- Runs the function passing the player object
        if checkCriteria then
-- Checks if the function returned a true boolean
            local chatTagInfo = {TagText = chatTag["Name"], TagColor = chatTag["Color"]}
 -- Creates the tag information for the tag.
            table.insert(playerChatTags, index, chatTagInfo);
-- Adds the tag to the initated table
        end
    end
    if #playerChatTags > 0 then
-- Checks to make sure there are actual tags in the table.
        speaker:SetExtraData("Tags", playerChatTags); 
 -- Sets the tag data.
    end
end)

Step Seven

Great! We got the hard work done. Now let's create our first chat tag for the game owner. I will comment what each line does.

You will need to edit this in that module we created prevously.

return {
    {
        ["Name"] = "Owner",
 -- The name of that chat tag.
        ["Color"] = Color3.fromRGB(56,26,0),
 -- The color of the chat tag
        ["checkCriteria"] = function(player) -- The function to check if the user should have the tag
            if player.UserId == game.CreatorId then -- Checks to see if the player's userID is the creators UserID
                return true; -- Returns that the tag is valid for this player
            end
        end
    }
}

Final

Let's see if that works.

img|80x45

Great! It worked (even though tthe color is horrible we can still change that later)

I hope you enjoyed this tutorial as it took me a long time to write.

Thanks,

    uhTeddy.

View in-game to comment, award, and more!