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
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.
Create a Folder and paste that in the folder.
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"));
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 {
}
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.
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)
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
}
}
Let's see if that works.
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.