What do you want to achieve? Keep it simple and clear!
I want to be able to enable and disable group chat tags by saying “!tags”
What is the issue? Include screenshots / videos if possible!
By default tags should be off so, when saying the command (!tags) it should run the script and work, but that isn’t the case here for some reason. So what I did was see if the Player.Chatted function was functioning itself by testing it using a simple print command, it still didn’t work (no print in output). But then when I removed the local ChatService variable, the Player.Chatted function worked.
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
All I’m guessing is that the local ChatService could be interfering with the actual chat tag script, not exactly sure what’s going on.
I’m a beginner at this, so I used the message function based on my knowledge. Here’s the script. What went wrong?
local GroupId = 32456991
local ServerScriptService = game:GetService("ServerScriptService")
local ChatService = require(ServerScriptService:WaitForChild("ChatServiceRunner"):WaitForChild("ChatService"))
local Players = game:GetService("Players")
local tags = {
[255] = {{TagText = "Owner", TagColor = Color3.fromRGB(0, 255, 150)}}, -- 255 is the Faction Leader / Owner Chat Tags
}
game.Players.PlayerAdded:Connect(function(player)
player.Chatted:Connect(function(message)
if message == "!tags" then
ChatService.SpeakerAdded:Connect(function(PlrName)
local Speaker = ChatService:GetSpeaker(PlrName)
local Player = Players[PlrName]
local Tag = tags[Player:GetRankInGroup(GroupId)]
if Tag then
Speaker:SetExtraData("Tags", Tag)
Speaker:SetExtraData("ChatColor", Color3.fromRGB(0, 255, 150))
end
end)
end
end)
end)
-- Services
local ServerScriptService = game:GetService("ServerScriptService")
local ChatService = require(ServerScriptService:WaitForChild("ChatServiceRunner"):WaitForChild("ChatService"))
local Players = game:GetService("Players")
-- Functions
local GroupId = 32456991
local Tags = {
[255] = {{TagText = "Owner", TagColor = Color3.fromRGB(0, 255, 150)}}, -- 255 is the Faction Leader / Owner Chat Tags
}
-- Functions
local function OnPlayerAdded(player)
-- Variables
local tagEnabled = false
local speaker
repeat task.wait()
speaker = ChatService:GetSpeaker(player.Name)
until (type(speaker) == "table")
-- Connections
player.Chatted:Connect(function(message)
if (message == "!tags") then
local tag = Tags[player:GetRankInGroup(GroupId)]
speaker:SetExtraData("Tags", tagEnabled and {} or tag)
speaker:SetExtraData("ChatColor", tagEnabled and Color3.new(1, 1, 1) or tag[1].TagColor)
tagEnabled = (not tagEnabled)
end
end)
end
-- Initialize
for _, player in pairs(Players:GetPlayers()) do
OnPlayerAdded(player)
end
-- Connections
Players.PlayerAdded:Connect(OnPlayerAdded)
I initialized players who might have joined before the PlayerAdded signal was connected. I removed ChatService.SpeakerAdded as it was unnecessary. Instead, I replaced it with GetSpeaker, which I placed in a loop until it was founded. Additionally, I introduced the tagEnabled variable to toggle the activation and deactivation of the tag.
If my response meets your satisfaction, you can select it as the solution. If you have any questions, feel free to ask me. Happy to help.
To my knowledge, it is not deprecated. There are currently two versions of the chat: one that uses TextChatService and the other is named LegacyChatService. You can switch between them by changing the value of the ChatVersion property in TextChatService, which is available in the Explorer. To achieve what our colleague is attempting, it will be challenging with TextChatService since, to my knowledge, it only works on the client side. Therefore, they would need to use remotes to signal the changes to other clients, which is not desirable due to its complexity. In contrast, LegacyChatService can handle tag activation or changes without the constant use of remotes to signal newcomers, departures, and tag changes because it managed on the server side. If you know of a way to change tags with TextChatService on the server, I would appreciate it if you could share it here, as it could be helpful for me and other developers.
Thank you so much, that works! One more thing, how would I be able to add multiple group ranks into the script involved (for group moderators, admins, etc.)?
The GetRankInGroup Player function returns the player’s rank in the group as an integer between 0 and 255, where 0 is a non-member and 255 is the group’s owner.