Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 5 years ago
Edited 5 years ago

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)
0
It’s Player.UserId, not Player.userId. User#19524 175 — 5y
0
I am getting the same error. It was working until I enabled studio access to API services awesomeipod 607 — 5y
0
It automatically fixed for me after editing in studio.. weird awesomeipod 607 — 5y
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. SBlankthorn 329 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

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

Ad

Answer this question