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
It’s Player.UserId, not Player.userId.
I am getting the same error. It was working until I enabled studio access to API services
It automatically fixed for me after editing in studio.. weird
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.