Gamepass tag that overlays group tag?

Hello, this script gives players a custom chat if in a group although I’m working on adding a gamepass tag that gives them another tag before the group one but I’m not sure on how I could implement that. Help or suggestions are appreciated.

local ServerScriptService = game:GetService("ServerScriptService")
local ChatService = require(ServerScriptService:WaitForChild("ChatServiceRunner"):FindFirstChild("ChatService"))
local Players = game:GetService("Players")

local Tags = {
	[255] = {{TagText = "Lead Developer", TagColor = Color3.fromRGB(255, 0, 120)}},
	[254] = {{TagText = "Contributor", TagColor = Color3.fromRGB(0, 255, 100)}},
	[1] = {{TagText = "Member", TagColor = Color3.fromRGB(255,0,0)}}
}

ChatService.SpeakerAdded:Connect(function(Player)
	local Speaker = ChatService:GetSpeaker(Player)
	local Player = Players[Player]
	local Tag = Tags[Player:GetRankInGroup(13738768)]

	if Tag then
		Speaker:SetExtraData("Tags", Tag)
	end
end)

You’ll need to use marketplace’s UserOwnsGamePassAsync API method to determine if the player owns the gamepass.

local marketplace = game:GetService("MarketplaceService")
local userOwnsGamePassAsync = marketplace.userOwnsGamePassAsync

local gamePassId = 0 --Change to gamepass's ID.

local function hasPass(player)
	local tries = 0
	repeat
		local success, result = pcall(userOwnsGamePassAsync, marketplace, player.UserId, gamePassId)
		if success then
			return result
		else
			warn(result)
			tries += 1
		end
	until tries >= 3
	return nil
end

Here’s a script which achieves that, all you need to do is call the function with the player instance you wish to query.

It’ll return true if the user owns the gamepass & false if otherwise. Additionally, it’ll return nil if the request for whatever reason fails after three attempts.

1 Like