What do you want to achieve? Keep it simple and clear!
I want to run specific code on the server immediately after a player purchases a gamepass successfully.
What is the issue? Include screenshots / videos if possible!
After a player purchases a gamepass, a RemoteEvent is fired. It is then listened to by the server and the server further checks if the player really has the gamepass using MarketplaceService:UserOwnsGamepassAsync() function. But for some reason, it returns false, even though the player just bought the gamepass and now owns it.
Making the player rejoin the server is unideal as the player would lose certain temporary progress that has no need of saving (but is still important), and creating a separate DataStore for it makes no sense.
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I searched a bit on the DevForum prior and read that it takes a bit of time to cache the data, which is why the game doesn’t realise the player bought the gamepass yet. But, this code needs to be run IMMEDIATELY after the player buys a gamepass, no delay can be tolerated.
Before you ask why check if the player owns the gamepass from the server separately, it’s because the Client is NOT to be trusted for prominent game mechanics as exploiters can easily manipulate the client; so it’s best to clarify important information sent from the client before taking in effect.
Please help if you can, I will mark your reply as a solution if it works!
Yeah, UserOwnsGamePassAsync does use cached data. There is one way to check.
Please note that this has been previously vulnerable to an exploit, I’m not sure if it still is, but you should definitely check.
--ON THE SERVER
game:GetService("MarketplaceService").PromptGamePassPurchaseFinished:Connect(function(player: Player, id: number, purchased: boolean)
if purchased then
--your code
end
end)
This was exploitable through exploiters calling MarketplaceService:SignalPromptGamePassPurchaseFinished, a method only supposed to be called by core scripts. Please double check before using this.
I did some research and found out that using MarketplaceService.ProcessReceipt() is a way to bypass this exploit loophole. Problem is however, I can’t seem to understand this function.
I made a new Script in ServerScriptService, specifically for handling receipts and purchases. This is the script currently, but I’m unsure of how to proceed further:
local MPS = game:GetService("MarketplaceService")
local IDs = {
[949918410] = "UnlimitedStorageGamepass"
}
MarketplaceService.ProcessReceipt callback only works for developer products. The best you can do is the code snippet I provided. It’s quite a major exploit, I’d be surprised if Roblox hadn’t patched it by now.
I did some research and Roblox is aware of it, but still no patches have been issued. And your code snippet did indeed work, so I’ll mark it as a solution.
Thank you!