GamePass recognition problems in the script

Hello Develepers, i have a Problem in one of my games, i tryed to make a Script that make a Imagebutton visible, when the Player hast a specific Gamepass. The Image Button is in a frame in the screenGUI ( screenGUI IS in the starterGUI ). But every time i try to Script IT, Something IS not working :frowning:

I Made the Script in a localscript in the screenGUI in the starterGUI, i have Made a imagelabel named: GirlVIP

Tere IS the Script:

local imageButton = script.Parent:WaitForChild("GirlVIP") -- Referenz zum ImageButton
local gamePassId =  123456789 -- i will soon Change IT to the real ID

local player = game.Players.LocalPlayer
local playerId = player.UserId

local function hasGamePass(playerId, gamePassId)
    local success, result = pcall(function()
        return game:GetService("MarketplaceService"):UserOwnsGamePassAsync(playerId, gamePassId)
    end)
    if success then
        return result
    else
        warn("Fehler bei der Überprüfung des GamePass-Besitzes: " .. tostring(result))
        return false
    end
end

if hasGamePass(playerId, gamePassId) then
    imageButton.Visible = true
else
    imageButton.Visible = false
end

try returning true instead of result

1 Like

Ok, IS that the only thing that is wrong or give it more things that i have to Change ?

mb you can just return the HasGamePass

1 Like
local Mps = game:GetService("MarketplaceService")
local imageButton = script.Parent:WaitForChild("GirlVIP") -- Referenz zum ImageButton
local gamePassId =  123456789 -- i will soon Change IT to the real ID

local player = game.Players.LocalPlayer
local playerId = player.UserId

local function hasGamePass(playerId, gamePassId)
local HasGamePass = Mps:UserOwnsGamePassAsync(playerId, gamePassId)
return HasGamePass
end

if hasGamePass(playerId, gamePassId) then
    imageButton.Visible = true
else
    imageButton.Visible = false
end
1 Like

What are you meaning with Return the gamepass ?

could you specify the problem, you’ve told us that something is wrong with the script causing it to not work, but you havent told us what specifically is happening / not happening

giving us any errors that are showing up will also help

1 Like

It’s solved I think already :+1:

Yes it is working thankyou for the script and help :slight_smile:

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