I am trying to make a leaderboard which has a VIP tag for whoever has the VIP gamepass. However, when I wrote the function to check if the player has the gamepass, it kept saying I dont have it even though I do. I tried looking for solutions on the devforum with no luck. Here’s the function:
local MarketplaceService = game:GetService("MarketplaceService")
local function checkVIPPass(userId)
local success, result = pcall(function()
return MarketplaceService:UserOwnsGamePassAsync(userId, 72736772590852)
end)
if success then
if result then
print("The player has unlocked the gamepass!")
return true
else
print("The player hasn't unlocked the gamepass.")
return false
end
else
print("Error checking gamepass: ", result)
end
end
And here’s the snippet of code using this function:
local function updateLeaderboardDisplay(boardType, leaderboardData)
local container = LeaderboardFolder[boardType].Container.ScrollingFrame
for _, child in pairs(container:GetChildren()) do
if child:IsA("CanvasGroup") and child.Name ~= "Sample" then
child:Destroy()
end
end
for position, entry in ipairs(leaderboardData) do
local playerId = tonumber(entry.UserId) or 0
local money = entry.Money or 0
local playerName = "Unknown"
local username = "Unknown"
local player = Players:GetPlayerByUserId(playerId)
if player then
playerName = player.DisplayName
username = player.Name
else
local success, fetchedUsername = pcall(function()
return Players:GetNameFromUserIdAsync(playerId)
end)
if success then
username = fetchedUsername
playerName = username
else
warn("Failed to fetch username for UserId:", playerId)
end
end
local clone = container.Sample:Clone()
clone.Name = tostring(position)
clone.Visible = true
clone.Parent = container
local PLACEHOLDER_IMAGE = "rbxassetid://0"
local content, isReady = Players:GetUserThumbnailAsync(playerId, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size420x420)
clone.PlayerHeadshot.Image = (isReady and content) or PLACEHOLDER_IMAGE
clone.PlayerInfo.UsernameFrame.DisplayName.Text = playerName
clone.PlayerInfo.UsernameFrame.Username.Text = "@" .. username
clone.PlayerInfo.Stats.MoneyText.Text = formatMoney(money)
if checkVIPPass(playerId) then
clone.PlayerInfo.UsernameFrame.VIPTag.Visible = true
else
clone.PlayerInfo.UsernameFrame.VIPTag.Visible = false
end
end
end
If anyone has a solution for this issue, please let me know. Thanks!