I have staff tags, but I also have vip tags for gamepass owners. If a staff buys the vip pass, it overrides their staff tag and only shows vip. How can I make the staff one priority?
Can you show us the tagging code? You have to have at least tried to fix it.
Tagging staff:
local Module = Storage:WaitForChild("ChatServiceRunner").ChatService
local Market = game:GetService("MarketplaceService")
local Chat = require(Module)
Chat.SpeakerAdded:Connect(function(Name)
if game.Players:FindFirstChild(Name) then
local Player = game.Players:FindFirstChild(Name)
local Speaker = Chat:GetSpeaker(Name)
if Player.UserId == 776294655 then --
Speaker:SetExtraData("Tags", {{TagText = "Creator", TagColor = Color3.fromRGB(85, 170, 255)}}) --
Speaker:SetExtraData("ChatColor", Color3.new(0,0,255)) --
elseif Player.UserId == 387060256 then
Speaker:SetExtraData("Tags", {{TagText = "Melon Shark", TagColor = Color3.fromRGB(85, 170, 255)}})
Speaker:SetExtraData("ChatColor", Color3.new(85, 170, 255))
elseif Player.UserId == 157066100 then
Speaker:SetExtraData("Tags", {{TagText = "Moderator", TagColor = Color3.fromRGB(255, 255, 0)}})
Speaker:SetExtraData("ChatColor", Color3.new(255, 255, 0))
elseif Player.UserId == 278133397 then
Speaker:SetExtraData("Tags", {{TagText = "Moderator", TagColor = Color3.fromRGB(34,139,34)}})
Speaker:SetExtraData("ChatColor", Color3.new(34,139,34))
elseif Player.UserId == 246403810 then
Speaker:SetExtraData("Tags", {{TagText = "Moderator", TagColor = Color3.fromRGB(255,0,0)}})
Speaker:SetExtraData("ChatColor", Color3.new(221,214,225))
elseif Player.UserId == 144157339 then
Speaker:SetExtraData("Tags", {{TagText = "Developer", TagColor = Color3.fromRGB(0,255,0)}})
Speaker:SetExtraData("ChatColor", Color3.new(0,255,0))
elseif Player.UserId == 125293735 then
Speaker:SetExtraData("Tags", {{TagText = "Owner", TagColor = Color3.fromRGB(255,0,0)}})
Speaker:SetExtraData("ChatColor", Color3.new(255,0,0))
elseif Player.UserId == 1498144377 then
Speaker:SetExtraData("Tags", {{TagText = "Developer", TagColor = Color3.fromRGB(0,35,102)}})
Speaker:SetExtraData("ChatColor", Color3.new(0,35,102))
elseif Player.UserId == 413969295 then
Speaker:SetExtraData("Tags", {{TagText = "Moderator", TagColor = Color3.fromRGB(128,0,0)}})
Speaker:SetExtraData("ChatColor", Color3.new(128,0,0))
end
end
end)
Tagging vip players:
local service = game:GetService("MarketplaceService")
game.Players.PlayerAdded:Connect(function(player)
if (service:UserOwnsGamePassAsync(player.UserId, gamepassId)) then -- check if have gamepass
local tags = { -- table for tags
{ -- first tag
TagText = "VIP", -- Tag text
TagColor = Color3.fromRGB(239, 184, 56) -- TagColor
}
}
local ChatService = require(game:GetService("ServerScriptService"):WaitForChild("ChatServiceRunner").ChatService) -- Get chat service
-- Get speaker
local speaker = nil
while speaker == nil do
speaker = ChatService:GetSpeaker(player.Name)
if speaker ~= nil then break end
wait(0.01)
end
speaker:SetExtraData("Tags",tags) -- Set tags
speaker:SetExtraData("ChatColor",Color3.fromRGB(239, 184, 56)) -- Change chat color, and dont use BrickColor.new(...).Color
end
end)```
U can modify ur check system, so if speaker ~= nil and playerId == 8474747373 and playerId == 2239383838 …
Easier and better way to do it.
local Tags = {};
--for each tag do this
table.finsert(Tags, {TagText = "This is a tag!"; TagColor = Color3.fromRGB(0, 162, 255);});
--Then after all that set their tags.
speaker:SetExtraData("Tags", Tags);
You aren’t using the API properly, nor are you using the API pieces that are provided that would make your work easier ten fold. Remember that the Lua Chat Speaker system also supports non-player speakers. Don’t use Player service at all, use SpeakerAdded and ChatSpeaker’s GetPlayer method.
The easiest way to resolve this problem is to address specialised tags first (and please use a dictionary, not a mess-train of if statements) and then VIP tags. A simple boolean flag, or even just checking if the player hasn’t had any tags set yet, could be enough to prevent overlapping.
It’s nice that you made an attempt though, but please in the future don’t write few-sentence threads and include as much detail as you can in the OP. If you just leave a few sentences, people need to ask questions just to figure out some basic information like what you’re currently working with and it slows down the process to getting a solution in a timely manner.
Anyway, with my advice in mind, there’s a couple of tweeks you can apply to your code. Do this all in one script as well to keep similar tasks in the same script.
local ServerScriptService = game:GetService("ServerScriptService")
local MarketplaceService = game:GetService("MarketplaceService")
local ChatServiceRunner = ServerScriptService:WaitForChild("ChatServiceRunner")
local ChatService = require(ChatServiceRunner.ChatService)
-- Create a dictionary of special chat data (e.g. mods).
local SPECIAL_CHAT_DATA = {
-- I will only fill out one dictionary key for you as an example, do
-- the rest on your own time.
[776294655] = {
ChatColor = Color3.new(0, 0, 255),
Tags = {
{TagText = "Creator", TagColor = Color3.fromRGB(85, 170, 255)},
}
},
-- etc
}
-- Again, make a table as a constant so you can edit here instead of
-- in a function. Your original code was creating tables every time
-- the function was called, which isn't good anyhow.
local VIP_CHAT_DATA = {
ChatColor = Color3.fromRGB(239, 184, 56),
Tags = {
{TagText = "VIP", TagColor = Color3.fromRGB(239, 184, 56)},
},
}
-- So if we need to change the pass, we can do it from here instead of
-- further into the code where it's less visible.
local GAME_PASS_ID = 0
-- Small tip: for the above tables, you can make submodules that return tables
-- on require. Would keep giant tables from being in the tags script.
-- To make things cleaner for us, to isolate this assignment bit and
-- to clearly show for example's sake, created this function.
local function applyExtraDataForSpeaker(speaker, dataTable)
for key, value in pairs(dataTable) do
speaker:SetExtraData(key, value)
end
end
-- Make sure to create a function like this. To catch speakers who may be added
-- ahead of SpeakerAdded being registered, some may not get tags.
local function speakerAdded(speakerName)
local speaker = ChatService:GetSpeaker(speakerName)
-- Player is available here! Do not use Players service!
local player = speaker:GetPlayer()
-- If this is a player speaker, proceed
if player then
-- Keep this flag handy for later.
local dataAddressed = false
-- Look for special data first: if they have it, apply it
local specialData = SPECIAL_CHAT_DATA[player.UserId]
if specialData then
applyExtraDataForSpeaker(speaker, specialData)
-- Flip our earlier flag dataAddressed for the if statement below
dataAddressed = true
end
-- Use the flag to determine if we should evaluate VIP next
if not dataAddressed then
local isVIP = MarketplaceService:UserOwnsGamePassAsync(player.UserId, GAME_PASS_ID)
-- If the player owns the VIP pass, give them VIP chat data. Our
-- earlier flag isn't needed anymore, so don't set it here.
if isVIP then
applyExtraDataForSpeaker(speaker, VIP_CHAT_DATA)
end
end
end
end
-- Hook the speakerAdded function to the SpeakerAdded event
-- and make sure all added speakers who didn't have
-- SpeakerAdded fired for them, gets the function called on them.
ChatService.SpeakerAdded:Connect(speakerAdded)
for _, speakerName in ipairs(ChatService:GetSpeakerList()) do
speakerAdded(speakerName)
end
Notice that I completely rooted this to the ChatService API? No unnecessary loops or anything and you don’t need anything like a priority system. To prevent overlapping, simple boolean variables are enough for this situation.
I find that things are slightly easier to comprehend if you read it out like it’s English.
Make a flag, whether we gave data in the past or not. Search for special data: do they have it? If yes, give them that data and turn on the flag, otherwise do nothing. Later, let’s check that flag to see if the special data if statement did anything. Is it still false? If yes, then let’s move on to checking if the user has the VIP game pass. They do? Got it, give them the VIP chat data.