Quick chat tags tutorial!

Hey there!
Today I will be showing you how to make a unique chat tag in roblox!

So first you will need to get the local player who is getting the tag, so type:

local players = game:GetService("Players")

After that you will need to get the chat service by typing:

local chatService = require(game.ServerScriptService:WaitForChild("ChatServiceRunner"):WaitForChild("ChatService"))

After that you will need to tell roblox what players will get the tags by typing:

local tags = { [PlayersUserIdHere] = {TagText = "TagName", TagColor = Color3.fromRGB(TagColor)}, }

We use the players UserId incase they change their name!

After that you need to detect if someone has spoken in chat by typing:

chatService.SpeakerAdded:Connect(function(playerName)

end)

Then you will need to get the speakers name and the player by typing:
chatService.SpeakerAdded:Connect(function(playerName)

local speaker = chatService:GetSpeaker(playerName)
local player = game.Players[playerName]
end)

Finally, you will need to detect if the player is detected as someone that should have a tag by typing:

if tags[player.UserId] then
speaker:SetExtraData("Tags",{tags[player.UserId]})

Final script:

local players = game:GetService("Players")

local chatService = require(game.ServerScriptService:WaitForChild("ChatServiceRunner"):WaitForChild("ChatService"))

local Admins = {

'PlayerName', 'PlayerName2'

}

local tags = {

[PlayersUserIdHere] = {TagText = "TagName", TagColor = Color3.fromRGB(TagColor)},
}

chatService.SpeakerAdded:Connect(function(playerName)

local speaker = chatService:GetSpeaker(playerName)

local player = game.Players[playerName]

if tags[player.UserId] then

speaker:SetExtraData("Tags",{tags[player.UserId]})
end
end)

I hope this helped!

9 Likes

Hey there!

One thing I’d recommend about the tutorial…

When it comes to formatting script and (more specifically) formatting more than one line, I would suggest highlighting the whole part of the script instead of just line by line. It produces a better result when showing off-script.

local players = game:GetService("Players")

local chatService = require(game.ServerScriptService:WaitForChild("ChatServiceRunner"):WaitForChild("ChatService"))

local Admins = {

'PlayerName', 'PlayerName2'

}

local tags = {

[PlayersUserIdHere] = {TagText = "TagName", TagColor = Color3.fromRGB(TagColor)},
}

chatService.SpeakerAdded:Connect(function(playerName)

local speaker = chatService:GetSpeaker(playerName)

local player = game.Players[playerName]

if tags[player.UserId] then

speaker:SetExtraData("Tags",{tags[player.UserId]})
end
end)

Like so:

2 Likes

Instead of fetching the player by indexing game.Players, you can just do speaker:GetPlayer()

7 Likes

Ah, thank you for the feedback!

1 Like