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