The script below should add a chat tag and color to the players who own the gamepass, but it only changes the chatcolor and not the tag for me, help
local ServerScriptService = game:GetService("ServerScriptService")
local MarketplaceService = game:GetService("MarketplaceService")
local ChatService = require(ServerScriptService:WaitForChild("ChatServiceRunner").ChatService)
local GAME_PASS_ID = 123456
local VIP_TAGS = {
{
TagText = "šVIP",
TagColor = Color3.new(0, 1, 1)
}
}
local function speakerAdded(speakerName)
local speaker = ChatService:GetSpeaker(speakerName)
local player = speaker:GetPlayer()
-- ChatSpeaker belongs to a player entity
if player then
if MarketplaceService:UserOwnsGamePassAsync(player.UserId, GAME_PASS_ID) then
speaker:SetExtraData("Tags", VIP_TAGS)
speaker:SetExtraData("ChatColor", Color3.fromRGB(0, 226, 226))
end
end
end
ChatService.SpeakerAdded:Connect(speakerAdded)
for _, speaker in ipairs(ChatService:GetSpeakerList()) do
speakerAdded(speaker)
end
I tested your script using a pass id I own, it worked perfectly so I assume the issue isnāt related to UserOwnsGamePassAsync. Does the script work in empty baseplates? and do you have any scripts/plugins which manipulate the chat?
Some advice from a design perspective that might help you debug this or similar issues. You ought have one and only one thing in your game that determines if someone is a VIP. For example, a BoolValue or attribute in/on the player. The value should come from a single call to UserOwnsGamePassAsync (or whatever its value depends on), probably from a script whose job it is to load benefits like that.
Individual features that read from the VIP status should use that just one thing - rather than the underlying API (UserOwnsGamePassAsync). So, your chat module, as well as any VIP doors or chat commands, etc, should read it. This makes it easy to debug individual features without having to meet worry about the underlying criteria. You decouple the āhas the passā and āhas VIP statusā meanings, which helps a lot during debugging.
Oh, I totally didnāt notice this at first, but you should change this to be a proper chat module: a ModuleScript in a folder named ChatModules in ChatService. Make sure to add an InsertDefaultModules BoolValue, true, into that folder as well. This is according to the Lua Chat System; either a client module or server module should work for your purposes.
I took the liberty to refactor your original code into a proper chat module:
local ServerScriptService = game:GetService("ServerScriptService")
local MarketplaceService = game:GetService("MarketplaceService")
--local GAME_PASS_ID = 123456
local VIP_TAGS = {
{
TagText = "šVIP",
TagColor = Color3.new(0, 1, 1)
}
}
return function (ChatService)
local function speakerAdded(speakerName)
local speaker = ChatService:GetSpeaker(speakerName)
local player = speaker:GetPlayer()
-- ChatSpeaker belongs to a player entity
if player then
--if MarketplaceService:UserOwnsGamePassAsync(player.UserId, GAME_PASS_ID) then
if true then
speaker:SetExtraData("Tags", VIP_TAGS)
speaker:SetExtraData("ChatColor", Color3.fromRGB(0, 226, 226))
end
end
end
ChatService.SpeakerAdded:Connect(speakerAdded)
for _, speaker in ipairs(ChatService:GetSpeakerList()) do
speakerAdded(speaker)
end
end
Looking at the documentation for ChatSpeaker:SetExtraData, it says that this extra data will be attached to a message if none is explicitly provided with the message. Maybe all messages being sent by VIP members already have Tag data?
You could try connecting to the ChatSpeaker.SaidMessage event and check the messageās ExtraData.Tags.
speaker.SaidMessage:Connect(function(message)
print(message.ExtraData and message.ExtraData.Tags)
end)
It also said in the documentation for ChatMessage.ExtraData that ExtraData.Tags is an array of strings, not an array of dictionaries, but I donāt trust that at all if you tried your current method before and it worked.
This feels like a total shot in the dark just from reading the docsā¦
It would be inserted right after setting the speakerās chat color in the speakerAdded function.
-- ChatSpeaker belongs to a player entity
if player then
if MarketplaceService:UserOwnsGamePassAsync(player.UserId, GAME_PASS_ID) then
speaker:SetExtraData("Tags", VIP_TAGS)
speaker:SetExtraData("ChatColor", Color3.fromRGB(0, 226, 226))
speaker.SaidMessage:Connect(function(message)
print(message.ExtraData and message.ExtraData.Tags)
end)
end
end
This was to debug if you are using the chat API correctly, which it seems you are. Think of it like removing a potentially bad lightbulb from a socket (the if UserOwnsGamePassAsync(...) then etc) and putting in a working lightbulb (if true then).
local function speakerAdded(speakerName)
local speaker = ChatService:GetSpeaker(speakerName)
local player = speaker:GetPlayer()
-- ChatSpeaker belongs to a player entity
if player then
if MarketplaceService:UserOwnsGamePassAsync(player.UserId, GAME_PASS_ID) then
speaker:SetExtraData("Tags", VIP_TAGS)
speaker:SetExtraData("ChatColor", Color3.fromRGB(0, 226, 226))
speaker.SaidMessage:Connect(function(message)
print(message.ExtraData and message.ExtraData.Tags)
end)
end
end
ChatService.SpeakerAdded:Connect(speakerAdded)
for _, speaker in ipairs(ChatService:GetSpeakerList()) do
speakerAdded(speaker)
end
āā
You forgot an end to close the speakerAdded function.
local ServerScriptService = game:GetService("ServerScriptService")
local MarketplaceService = game:GetService("MarketplaceService")
local ChatService = require(ServerScriptService:WaitForChild("ChatServiceRunner").ChatService)
local GAME_PASS_ID = 123456
local VIP_TAGS = {
{
TagText = "šVIP",
TagColor = Color3.new(0, 1, 1)
}
}
local function speakerAdded(speakerName)
local speaker = ChatService:GetSpeaker(speakerName)
local player = speaker:GetPlayer()
-- ChatSpeaker belongs to a player entity
if player then
if MarketplaceService:UserOwnsGamePassAsync(player.UserId, GAME_PASS_ID) then
speaker:SetExtraData("Tags", VIP_TAGS)
speaker:SetExtraData("ChatColor", Color3.fromRGB(0, 226, 226))
speaker.SaidMessage:Connect(function(message)
print(message.ExtraData and message.ExtraData.Tags)
end)
end
end
end
ChatService.SpeakerAdded:Connect(speakerAdded)
for _, speaker in ipairs(ChatService:GetSpeakerList()) do
speakerAdded(speaker)
end
Thatās because of the formatted quotation marks (because you didnāt place the code in a proper code block). Just highlight the left-hand quotation mark, press ctrl+f, and replace it with the character from your keyboard. Do the same with the right-hand quotation mark.
When you write quotes in your post like this, Discourse (the forum software) will render quotes as ācurly quotesā instead of "regular quotes". This is highly problematic when pasting code, so please remember to prefix it with ```lua