Gamepass chat tag doesnt work

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

When I pasted your code into a script in a blank game place, and replaced this line:

if MarketplaceService:UserOwnsGamePassAsync(player.UserId, GAME_PASS_ID) then

with this line:

if true then

It worked as expected. It seems that a yielding function like UserOwnsGamePassAsync may be causing you some issue.

Edit: Or, this could also be another script in your game. You should try to isolate the problem by running your code in a blank place.

1 Like

I replaced it and had the same result, I also tested the script out in 2 different games so i dont think its a script.

also changing it made people who dont own the pass chat color change too

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?

I have a script for a welcome message but thats all

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

But you made the ID of the gamepass commentary? how would it recognise it now

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…

Where does this part go in the script?

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).

I get this syntax error
image

1 Like

I don’t know why there’s a syntax error. What does your code look like now?

ā€˜ā€™
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 = ā€œ:crown: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

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

Sorry in advance for mixing whitespace.

Oh no, now the script is full of red lines

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

1 Like

I still dont have the tag, i think its just a me problem, weird…

1 Like