Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

I'm trying to make a gamepass enable an imagebutton, but it's not working?

So I have a game, and I want to make it so whenever the player has a gamepass, a imagebutton appears. But for some reason, this isn't working. It worked yesterday, and I honestly don't know what the problem could be, so can someone please review it and tell me if they see any errors?

Server Log: 19:33:25: Marketplace::UserOwnsGamePassAsync: Parsed Invalid JSON. Data may be corrupted. Stack Begin Stack End

Script:

local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local LocalPlayer = game:GetService("Players").LocalPlayer

local gamePassID = 4789729  -- Change this to your game pass ID 
 
function onPlayerSpawned(player) 

    local hasPass = false
 
    -- Check if the player already owns the game pass
    local success, message = pcall(function()
        hasPass = MarketplaceService:UserOwnsGamePassAsync(player.userId, gamePassID)
        print("BHammer Appeared In Inv")
    end)

    -- If there's an error, issue a warning and exit the function
    if not success then
        warn("Error while checking if player has pass: " .. tostring(message))
        return
    end
 
    if hasPass == true then
        LocalPlayer.PlayerGui:WaitForChild("Inventory").Frame.BHSignal.Visible = true
    end
end 

game.Players.PlayerAdded:connect(function(player)
  player.CharacterAdded:connect(function()
    onPlayerSpawned(player)
  end)
end)

-- Connect 'PlayerAdded' events to the 'onPlayerAdded()' function
Players.PlayerAdded:Connect(onPlayerSpawned)

4 comments

0

It’s Player.UserId, not Player.userId.

0

I am getting the same error. It was working until I enabled studio access to API services

0

It automatically fixed for me after editing in studio.. weird

0

Lol Sorry for the stupidity, I had just transferred my game from a player creation to a group creation, and COMPLETELY forgot that you had to buy gamepasses in a Group game, while you'd automatically have them in a player creation.

1 answer

I am very, very, sorry for the stupidity of this. I had just transferred this game from a player creation, to a group creation, and thus the gamepasses In my old game wouldn't work. So I made new ones in the group game; But completely forgot that you wouldn't automatically obtain the gamepasses from a group game. So in the end, the error was I didn't have them purchased xD

This discussion is preserved as it was. New answers, comments, and votes are closed.