Buy Gamepass Animation

Hello developers, I’m impressed by the animations that are played when a player donates robux in pls donate. I wanted to ask how you can get an animation to play when the player buys a certain game pass.
I’ve already created an animation, I just don’t know how such a script is structured and where it has to be put (server script service or in a dummy that executes the animation). Could someone please explain this to me in detail since I don’t know much about scripts?

1 Like

You would use a script to detect when the purchase has finished.

local mps = game:GetService("MarketplaceService")

--can't remember if player parameter is Player or UserId sorry
local function onPurchaseFinished(player: Player|number, id: number, purchased: boolean)
    if purchased then
        --gamepass was purchased, play animation
    end
end

mps.PromptGamePassPurchaseFinished:Connect(onPurchaseFinished)

If you’re doing this for developer products, use ProcessReceipt instead. You will need different code for that.

2 Likes

Do i have to write the ID in the Script, and where do i Put the script in ( in a Script, or in a localscript, in the Button the Player hast to cklick ON when He wants to buy it, or in the ServerScriptService?)

It’ll be a script in ServerScriptService. Do anything you want to do if they bought it in place if the --gamepass was purchased, play animation. Yes, you will also need to compare the gamepass IDs, I forgot about that:

if purchased and id == GAMEPASS_ID then
end
1 Like