Is there any advanced on checking gamepass?

Hello folks, I’m wondering. Is there any advanced method for checking gamepass?

function Constants.HasPass(player: Player, productId: number): boolean
	local success, hasPass = pcall(function()
		return Constants.Services.MarketplaceService:UserOwnsGamePassAsync(player.UserId, productId)
	end)
	if success then
		return hasPass
	else
		warn("Failed to check gamepass for player:", player.Name)
		return false
	end
end

At that point hasPass is the reason it failed with an actual error code message string.
Only thing I can see to add for “more advanced”… warn(player.Name…’ '…tostring(hasPass))

You can create a datastore and store all the purchased products in the datastore and then use that data to see if the player has game pass or not with this method you can add features for players to gift game passes and etc you can also add re-try attempts in your code and make it check if the player has game pass 5 times if not success than return false in case if the first attempt wasn’t successful

2 Likes

Could you clarify what you mean by ‘else’? im so confused. Fyi, sometimes hasPass returns false instead of true, so should i use haspass or true instead ? By the way, thank you for your suggestion!

Thank you for your suggestions! However, I don’t think it’s possible to gift someone a gamepass and Im pretty sure you were referring to Developer Products instead. But still, thank you for the help

with help of datastore you can make it possible :slight_smile: you could also store the original price the gamepass was purchased for

this is example data structure

{
 [1] = {
  {ProductId=0,Price=1}
  }
}

0 being the id of the gamepass / developer product

with the datastore you will have full control on saving,updating and loading players gamepasses

Uh, what? As far as I remember, Roblox does not natively support gifting gamepass. So, will the game pass be labeled as ‘Owned’ after I gift it to someone ( outside game ) ?

roblox doesnt offer the support for it but you can make your own system using roblox datastores

  1. player purchases gamepass
  2. you save players data
  3. when player joins you load their gamepasses by checking their data

so instead of using “UserOwnsGamePassAsync” you can also check if player has gamepass in their data what also gives you full control over how gamepasses work

Yeah, I agree with what you said, it’s a good one . However, I’m only about 50% on board because players can sometimes purchase game passes outside the game, which could lead to errors. Maybe we should check both scenarios?

Alright, this topic is too far from what I wanted. If you have any suggestions, lmk.

Really? First off the script is fine… But if you want to be super picky or “advanced”. There would be one other thing it could do. Right now it’s they passed or they failed. Really it’s they passed or they don’t have the gamepass OR there was an error. So three posssible outcomes.

local success, message = pcall(function()
		HasGamepass = MarketPlaceService:UserOwnsGamePassAsync(player.userId, gamepassID)
	end)

if not success then
	warn("Checking Gamepass "..tostring(message))
	return
end

if HasGamepass == true then print("Has GamePass")
else print("No GamePass")	
end

This shows all three…

MarketPlaceService:UserOwnsGamePassAsync has three possible returns…
True, Flase or the error message that made it cause an error.

1 Like