Hello, I was working on a script that would basically add tag to your name in chat and change your text color if you have sufficient rank in certain group, but the script isn’t working at all. Any idea what the problem could be?
local players = game:GetService("Players")
local serverScriptService = game:GetService("ServerScriptService")
local chatService = require(serverScriptService:WaitForChild("ChatServiceRunner"):WaitForChild("ChatService"))
chatService.SpeakerAdded:Connect(function(player)
local Speaker = chatService:GetSpeaker(player)
if player:GetRankInGroup(9965171) >= 254 then
Speaker:SetExtraData("Tags", {{TagText = "Central Directory", TagColor = Color3.fromRGB(128, 0, 128)}})
Speaker:SetExtraData("ChatColor", Color3.fromRGB(255, 198, 26))
elseif player:GetRankInGroup(9965171) <= 253 and player:GetRankInGroup(9965171) >= 250 then
Speaker:SetExtraData("Tags", {{TagText = "Administration", TagColor = Color3.fromRGB(230, 0, 230)}})
Speaker:SetExtraData("ChatColor", Color3.fromRGB(255, 198, 26))
else
end
end)
I used Print to see if I could find the problem, but even the chatService.SpeakerAdded:Connect(function(player) does not run.
--Script in ServerScriptService
local players = game:GetService("Players")
local serverScriptService = game:GetService("ServerScriptService")
local chatService = require(serverScriptService:WaitForChild("ChatServiceRunner"):WaitForChild("ChatService"))
chatService.SpeakerAdded:Connect(function(playerName) --the parameter returns the name of the player, not the userdata.
local speaker = chatService:GetSpeaker(playerName)
local player = speaker:GetPlayer() --getting player from speaker.
if not player then return end
if player:GetRankInGroup(2788849) >= 4 then
speaker:SetExtraData("Tags", {{TagText = "Central Directory", TagColor = Color3.fromRGB(128, 0, 128)}})
speaker:SetExtraData("ChatColor", Color3.fromRGB(255, 198, 26))
elseif player:GetRankInGroup(2788849) <= 3 and player:GetRankInGroup(9965171) >= 250 then
speaker:SetExtraData("Tags", {{TagText = "Administration", TagColor = Color3.fromRGB(230, 0, 230)}})
speaker:SetExtraData("ChatColor", Color3.fromRGB(255, 198, 26))
end
end)