So I’m trying to make a script that gives the admins in my game a special chat tag and I’ve written some code and it doesn’t work but I don’t know why.
It does nothing, it does not give an error.
I looked for solutions on the dev forum but I found none that worked.
local Players = game:GetService('Players')
local SSS = game:GetService('ServerScriptService')
local admins = {1375761603, 22671011}
local CS = require(SSS:WaitForChild('ChatServiceRunner'):WaitForChild('ChatService'))
--admin tags
CS.SpeakerAdded:Connect(function(PlayerName)
local SP = CS:GetSpeaker(PlayerName)
if table.find(admins, PlayerName.UserId) then
SP:SetExtraData('NameColor', Color3.fromRGB(0, 255, 255))
SP:SetExtraData('ChatColor', Color3.fromRGB(159, 243, 233))
SP:SetExtraData('Tags', {{TagText = 'Admin', TagColor = Color3.fromRGB(255, 0, 0)}})
end
end)
The reason nothing is happening is because the “PlayerName” parameter seems to be just the player’s name, not the player object itself. Because of that, doing “PlayerName.UserId” will return nil.
To fix this, you simply just need to get the player object from the Players service, here’s your fixed code:
local Players = game:GetService('Players')
local SSS = game:GetService('ServerScriptService')
local admins = {1375761603, 22671011}
local CS = require(SSS:WaitForChild('ChatServiceRunner'):WaitForChild('ChatService'))
--admin tags
CS.SpeakerAdded:Connect(function(PlayerName)
local SP = CS:GetSpeaker(PlayerName)
local Player = Players:FindFirstChild(PlayerName) -- Get player object
if table.find(admins, Player.UserId) then
SP:SetExtraData('NameColor', Color3.fromRGB(0, 255, 255))
SP:SetExtraData('ChatColor', Color3.fromRGB(159, 243, 233))
SP:SetExtraData('Tags', {{TagText = 'Admin', TagColor = Color3.fromRGB(255, 0, 0)}})
end
end)
I’ve tested this myself and it worked, so if it somehow doesn’t, please reply back.