How to detect when gamepass ownership has changed

Hello everyone, I was just wondering how to detect when a player has bought a certain gamepass.

I made a gui that displays a lock on a certain weapon when the player doesn’t own the gamepass, but I want to hide the lock UI when the player buys the gamepass.

I thought of using MarketPlaceService.PromptPurchaseFinished, but that doesn’t work if they buy it from the Store tab on the game page.

I’m not too sure what you mean but I think I have an understanding but why don’t you try to check every couple of seconds if the player owns the gamepass?

local MarketPlaceService = game:GetService("MarketPlaceService")

local BoughtGamepass =  MarketPlaceService.UserOwnsGamePassAsync(game:GetService("Players").LocalPlayer.UserId, GAMEPASS_ID)

while wait(3) do
if BoughtGamepass then
   -- what to do here
end
end

Yeah, that’s what I was looking for. I’ve thought of using a while loop, but I’m not sure if it will cause lag or not.

I think the variable must go inside the loop, else it wont update because it will only kept storaged if the player had the gamepass before the loop started

Yea, that’s true as well, and I think using a while loop will work. Thanks!

Yeah he’s also right I believe but overall that script should be similar to what you need

That wouldn’t necessarily work.

If they owned it when they joined, it will always return true. They would have to rejoin for an updating result.

Hmm, then what should I do. Is there any other way to check if a player owns a gamepass without this behavior?

You could possible recreate the old behavior by creating a function that sends a proxy request to the roblox api page to see if the player still owns the gamepass. This would require knowledge of HttpService though.

I’m not all that familiar with HttpService other than using it to send messages to a discord server, but I’ll see what I can do.