UserOwnsGamePassAsync() Suddenly yielding code indefinitely

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!

I would like to know why UserOwnsGamePassAsync() is suddenly with no changes to my game indefinitely yielding code.

  1. What is the issue? Include screenshots / videos if possible!

When UserOwnsGamePassAsync() is called within a pcall. It never returns anything and stays stuck on that line of code. Occasionally it returns 500 server error. This has never happened until today and I’ve changed nothing.

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

I’ve ensured that the code is contained within a Pcall.

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

This is happening in a live game. It does not occur in studio. Although I’m fairly certain UserOwnsGamePassAsync() always returns false in studio

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

Update: this is also happening with badges

I am not familiar with roblox error codes but It is possible that the issue is caused by a server-side issue with Roblox, as this function relies on contacting the roblox servers. If this is the case, the issue can be resolved by contacting Roblox technical support.

1 Like

Ensure the gamepass is still available and not content deleted, make sure the id is the same in the script as on website.
The website seems to be working fine.

Is it possible to send a screenshot of the code or just post it here and of course without any sensitive information? Seems like an extremely odd error.

Here it is. Its in a module file thats run by a server script

local SvcMarket = game:GetService("MarketplaceService")
local GAMEPASS_ID = [Insert gamepass id]
local USER_ID = [InsertUserId here]



function Rewards.HasGamepass(userId, gamepassId)
	local success, result = pcall(function()
		print("Checking if user owns gamepass")
		return SvcMarket:UserOwnsGamePassAsync(userId, gamepassId)
	end)

	if success then
		if result then
			return true
		else
			return false
		end
	else
		warn("Issue checking gamepass status with roblox servers")
		return false
	end
	return false
end

local hasPass = Rewards.HasGamepass(USER_ID, GAMEPASS_ID) -- Code execution stops here
print(hasPass)

Perhaps it would work if we made a boolean out of it.

local SvcMarket = game:GetService("MarketplaceService")
local GAMEPASS_ID = [Insert gamepass id]
local USER_ID = [InsertUserId here]



function Rewards.HasGamepass(userId, gamepassId)
    local ownsPass = false

	local success, result = pcall(function()
		ownsPass = SvcMarket:UserOwnsGamePassAsync(userId, gamepassId)
	end)

	if success then
		return ownsPass
	else
		warn("Error when checking if a player owns the gamepass")
	end
end

local hasPass = Rewards.HasGamepass(USER_ID, GAMEPASS_ID) -- Code execution stops here
print(hasPass)

This entire code piece can be simplified to:

return sucessful and result

Why? Because if successful is true, it will return the result, which could be true or false.
If successful is false, it returns false.

I suggest not keeping the template text when you make a topic. It can sometimes be confusing because it is not part of your issue.

Are you sure that it’s yielding? Have you trying printing before and after the call?

If anyone else finds this I believe the cause was because I was slightly spamming the calls to UserOwnsGamePassAsync. It was being run way too often as a result likely being ignored by Roblox servers. Instead of running this code I made it so gamepass purchases are stored in the datastore then deserialized into an object on the player. Then check that for ownership instead of spamming Roblox servers.

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