I’m trying to make chat tags w/o having to go into the chat modules to keep everything clean and simple, but unfortunately it isn’t working in my favor.
I want to make a chat tag for beta testers who join my game, and creators, devs, mods, etc.
The tag should look something like [MOD][wayIxn]: Hello world! (I honestly dont care about the emoji.)
The code I currently have does not however, work. It’s in a server script:
local Players = game:GetService("Players")
local Storage = game:GetService("ReplicatedStorage")
local ScriptService = game:GetService("ServerScriptService")
local ChatService =
require(ScriptService:WaitForChild('ChatServiceRunner'):WaitForChild('ChatService'))
game.Players.PlayerAdded:connect(function(player)
if player.Stats.BetaTester.Value == true then
local Speaker
while not Speaker do
Speaker = ChatService:GetSpeaker(tostring(player.Name))
if Speaker then
break
end
wait()
end
print(Speaker)
Speaker:SetExtraData("NameColor", Color3.fromRGB(209, 193, 97))
Speaker:SetExtraData("ChatColor", Color3.fromRGB(178, 248, 229))
Speaker:SetExtraData("Tags", {{TagText = "Beta Tester", TagColor =
Color3.fromRGB(189, 83, 83)}})
end
end)
local Players = game:GetService('Players')
local ChatService = require(game:GetService('ServerScriptService'):WaitForChild('ChatServiceRunner'):WaitForChild('ChatService'))
Players.PlayerAdded:connect(function(player)
local speaker
while not speaker do
speaker = ChatService:GetSpeaker(player.Name)
wait()
end
if player.Name == "Rezault" then
speaker:SetExtraData("Tags", {{ TagText = "OWNER", TagColor = Color3.fromRGB(4, 175, 236) }})
speaker:SetExtraData("NameColor", Color3.fromRGB(85, 170, 0))
speaker:SetExtraData("ChatColor", Color3.fromRGB(239, 184, 56))
end
end)
Change the if player.Name == “Rezault” to whatever you wish, and make it whatever tag and colour you want.
@xuefei123 actually has a really good tutorial on this, and though it requires a bit more effort, I really like how it is much more organized and easy to use in my opinion. Read more here.
Thanks! It works. Do you know how I could add some type of “Priority” or make a player have more than one tag? Like [Head Developer][SomeTagHere][wayIxn]: Hello world!
You can assign another tag to a player by adding another table to the function where the tag is initially being assigned & I’m glad that my post had solved your issue!
local Players = game:GetService('Players')
local ServerScriptService = game:GetService('ServerScriptService')
local ChatService = require(ServerScriptService:WaitForChild('ChatServiceRunner'):WaitForChild('ChatService'))
local Administrators = {
'PlayerName1',
'PlayerName2'
}
ChatService.SpeakerAdded:Connect(function(PlayerName)
local Speaker = ChatService:GetSpeaker(PlayerName)
for i,v in pairs(Administrators) do
if (Players[PlayerName].Name == Administrators[i]) then
Speaker:SetExtraData('NameColor', Color3.fromRGB(209, 193, 97))
Speaker:SetExtraData('ChatColor', Color3.fromRGB(178, 248, 229))
Speaker:SetExtraData('Tags', {{TagText = 'Head Developer', TagColor = Color3.fromRGB(189, 83, 83)}, {TagText = 'SomeTagHere', TagColor = Color3.fromRGB(189, 83, 83)}})
end
end
end)
how would we add on and take away tags? lets say i have a menu and you can select which tag you want. i put on the developer tag, then put on the admin tag. then i want to take off the admin tag. how would i make it take away the tag and add the tag? (in different scripts too)
ChatSpeakers have a method called GetExtraData. You can pass Tags as the ExtraData key, then create a loop function that traverses through the table and removes a table where the TagText element is equal to a target value.
local speakerTags = ChatSpeaker:GetExtraData("Tags")
for _, Tag in pairs(speakerTags) do
if Tag.TagText == "Admin" then
table.remove(speakerTags, Tag)
end
end
ChatSpeaker:SetExtraData("Tags", speakerTags)
I don’t believe the last line is necessary if any changes to the table are automatically saved, considering tables are passed by reference. Try first without; if that doesn’t work, throw the SetExtraData statement back into your code.
Alternatively, if you’re just equipping tags and don’t have any other tag code, you could just avoid doing that completely and assign a tag based on your selection.
local function AdaptTag(Text, Color)
ChatSpeaker:SetExtraData("Tags", {
{
TagText = Text,
TagColor = Color
}
})
end
i was looking at this script and was trying to remove the ‘‘SomeTagHere’’ tag, and when trying to remove it i messed up the script, is there anyway to remove it without messing it up? (New to scripting)