Gamepass script not working

The purpose of this script is to give the player a billboard GUI above their head if they have purchased the relevant gamepass. When using the script without the gamepass check, it works perfectly fine and the GUI is cloned into my character’s head. I have looked at other dev forum posts and videos but the solutions in those haven’t worked either.

Script:

local marketplaceService = game:GetService("MarketplaceService")

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		local ownsPass = marketplaceService:UserOwnsGamePassAsync(player.UserId, 5069872012)
		if ownsPass == true then
			local VIPGui = game.ServerStorage.VIPGui:Clone()
			VIPGui.Parent = character.Head
		end
	end)
end)

I would be very grateful if someone could help me figure this out.

Not too versed on Gamepasses but maybe you used the AssetID instead of the Gamepass ID? (I’ve never used gamepasses so I may be horribly wrong lol)

Make sure you got the pass ID completely right, one small number can make it go all wrong.

Do you actually own the gamepass? That’s another reason.

Also, UserOwnsGamePassAsync should be wrapped in a pcall, I’m pretty sure.

local mps = game:GetService("MarketplaceService")

local success, owned = pcall(mps.UserOwnsGamePassAsync, mps, player.UserId, --[[gamepass ID here]])
if success and owned then
    --do stuff because they own it
elseif not success then
    player:Kick("Failed to retrieve gamepass data. Please rejoin!")
else
    --they don't own the pass.
end

Do you own the gamepass like you created it?? And Gamepass purchase made in studio dont saves.

1 Like

This worked. I was using the ID found on the website URL instead of the one you copy from the gamepass on the website. Thanks!

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