Chat Tag on Gamepass Purchase

Hello,

so I went through the forums and found this post:

which covers how chat tags work, however the problem I ran into is that the speakerAdded event fires once (as soon as the player joins) which means that it’s checking whether the player owns the gamepass once at the start. This brings about the problem that if a player purchases the gamepass while in-game, the chat tag won’t update.

Is there a solution for this?

1 Like

Would an event from MarketplaceService listening to if the player buys the gamepass whilst in game which updates the ChatSpeaker object work?

you should use

game:GetService("MarketPlaceService").PromptGamePassPurchaseFinished
1 Like

Idk how to update the ChatSpeaker object that’s the problem.
@sniper74will I do know how to use PromptGamePassPurchaseFinished event tho.

Check out the SetExtraData method on this page. You’d change it the same way you originally added the chat tags once you know they bought the gamepass.

1 Like

Oh I understood now. I think I got it. Thank you!

1 Like

here, use this to change the ChatSpeaker tag:

local tags = {
		{
		TagText = "VIP",
		TagColor = Color3.fromRGB(0, 255, 255)
	}
}
local ChatService = require(game:GetService("ServerScriptService"):WaitForChild("ChatServiceRunner").ChatService)
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)
speaker:SetExtraData("ChatColor",Color3.fromRGB(255, 254, 0))
1 Like

If you’re doing this from the server then you can combine the ChatService and PromptGamePassPurchaseFinished on the server (thankfully it does fire on the server according to documentation). In this case though you don’t want to use the SpeakerAdded event since you’re already listening to an event, use the GetSpeaker method to get an associated ChatSpeaker for the player.

local MarketplaceService = game:GetService("MarketplaceService")
local ServerScriptService = game:GetService("ServerScriptService")

local ChatService = require(ServerScriptService:WaitForChild("ChatServiceRunner").ChatService)

local VIP_GAME_PASS_ID = 0

local function passPurchased(player, gamePassId, wasPurchased)
    if gamePassId == VIP_GAME_PASS_ID and wasPurchased then
        local speaker = ChatService:GetSpeaker(player.Name)
        if speaker then
            -- Make your SetExtraData call here
            speaker:SetExtraData(...)
        end
    end
end

MarketplaceService.PromptGamePassPurchaseFinished:Connect(passPurchased)

Ideally you should handle this in the same place where you handle the VIP tags for a player that first enters so that you have access to the VIP chat data tables rather than having to put the same constants in two different scripts. For example, the code above can go along with the code sample that is listed in the post linked.

2 Likes