Why is my vip gamepass not giving me a chat tag?

so i followed a tutorial on the devforum on how to give anyone who has a gamepass a chat tag, so i made a brand new game to see if it works, but it isnt for me. what is wrong?
code:

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

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

local GAME_PASS_ID = 773271197

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

and before you ask, yes that is the correct gamepass number.

2 Likes

Are you using LegacyChatService or TextChatService? TextChatService requires different steps to add a chat tag.

Are there any errors?

when I run it, there are no errors, the chat tag just doen’t show up.
and I don’t know how to tell if im using LegacyChatService or TextChatService

Click the properties of the TextChatService in the explorer. What does the ChatVersion property say?

ahh ok, yes, I am using TextChatService

Your code should work if you switch it to LegacyChatService. However, it is in deprecation and is not recommended for new experiences. So, I would probably suggest this structure:

  • Have a script to manage the gamepass checking. Check on join and if they buy the gamepass, then set an attribute to true or false depending on whether they have the pass.
  • Use the TextChatService’s OnIncomingMessage callback to manage the chat tag. It will check for the attribute and add a tag accordingly.
--OnIncomingMessage can only be implemented in a LocalScript

local tcs = game:GetService("TextChatService")
local players = game:GetService("Players")

--this will handle the new message
local function addTag(message:TextChatMessage)
    if not message.TextSource then return nil end --if it was a system message
    
    --get the player
    local player = players:GetPlayerByUserId(message.TextSource.UserId)
    if not player then return nil end --if the player could not be found for whatever reason

    --set up the properties
    local properties = Instance.new("TextChatMessageProperties")

    --check the attribute
    if player:GetAttribute("YourPassAttribute") == true then --can't use logic statement as it would just check for the attribute
        --set the chat tag
        properties.PrefixText = `<font color="rgb(255, 255, 0)">[👑 VIP]</font> [{player.DisplayName}]`
    else
        properties.PrefixText = message.PrefixText
    end
    
    return properties
end

--set the callback
tcs.OnIncomingMessage = addTag

so i should use this and keep TextChatService?
and also should i have two scripts, or jut the one you sent?

Keep TextChatService. The script I sent should be able to add the chat tag if you change to your attribute, it should be a LocalScript. You will need to make a script server-side to add that attribute depending on whether the player has the gamepass.

how do i make a pass attribute? what do i put in, for it to equal " if the player has the badge"

So, you would have something like:

local mps = game:GetService("MarketplaceService")

local success, owned = pcall(mps.UserOwnsGamePassAsync, mps, player.UserId, gamepassId)

and then…

if not success then player:Kick() end

if owned then
    player:SetAttribute("VIP", true)
else
    player:SetAttribute("VIP", false)
end

Do the check whenever the player joins or the prompt for gamepass purchases finishes.

1 Like

thank you so much! this really heped

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.