Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do you fire a function after a gamepass has been purchased?

Hello,

Does anyone know how to fire a function after a gamepass has been purchased? This is my current script that is not working, I am not sure how to fix it!

local plr = game.Players.LocalPlayer
local Id = 5892397
script.Parent.MouseButton1Click:connect(function()
    game:GetService("MarketplaceService"):PromptGamePassPurchase(plr, Id)
end)

game:GetService("MarketplaceService"):PromptPurchaseFinished:connect(function(plr,Id,purchased)
	if purchased then
		game.ServerScriptService.GamePassCheck.LoadInventory:FireServer()
	end
end)

1 answer

✓ Accepted answer

The answer here is pretty simple, you would use the PromptGamePassPurchaseFinished() event for game passes , just like you would use the PromptPurchaseFinished for dev products.


PromptGamePassPurchaseFinished


the PromptGamePassPurchaseFinished event is an event of the marketplace service and has 3 arguments, the player instance, the game pass id , and a WasPurchased boolean.

PromptGamePassPurchaseFinished:Connect(function(plr,gamepassid,waspurchased)'

With that said, you can do the following:

local id = 214124124 --your gamepass id
local mps = game:GetService("MarketplaceService")

mps.PromptGamePassPurchaseFinished:Connect(function(plr,gpid,purchased)
	if purchased and gpid == id then
		...
	end
end)

Hopefully this helped!

1 comment

0

Thank you very much! It helped a lot!

This discussion is preserved as it was. New answers, comments, and votes are closed.