Giving inventory after buying gamepass

So I made a script that gives a gamepass technically just this:

local plr = game.Players.LocalPlayer
local id = blah 

script.Parent.MouseButton1Down:Connect(function()
game.MarketplaceService:PromptGamePassPurchase(plr, id)
end)

Now I need to know, how would I make it so it gives an item when you buy it?
What I am looking for is when you join the game, it gives it.
I am also looking for when you buy it, it immediately gives it once the transaction is successful.
Any ideas on how do give a certain tool after buying the gamepass?

2 Likes

You need to have them rejoin game so the ID can register or if it’s a coin/exp thing make it a DevProduct and just use a regular give script

Yea I know I need to make a script :confused:
But how would I make the script?

You can use MarketplaceService’s PromptGamepassPurchaseFinished event, it is pretty simple to be used like this:

local function gamepassPurchaseFinished(player, gamepassId, wasPurchased)
 --Here you may match gamepassId with the one you want to, and check if it wasPurchased and do the reward for the passed player.
end
 
MarketplaceService.PromptGamePassPurchaseFinished:Connect(gamepassPurchaseFinished)
1 Like

So I know this, but the main thing I am confused with is now how would it maybe clone the jackhammer (The gamepass item which is located in Game.ServerStorage.Jackhammer), to the starterpack, would I just do:

local function gamepassPurchaseFinished(player, gamepassId, wasPurchased)
Game.ServerStorage.Jackhammer:Clone()
end

 
MarketplaceService.PromptGamePassPurchaseFinished:Connect(gamepassPurchaseFinished)

So now I have bought the gamepass, cloned the jackhammer now how will I put this jackhammer into my hand so I can equipt it?

1 Like

So I have an idea, just to make sure this works?

local function gamepassPurchaseFinished(player, gamepassId, wasPurchased)
 local jackhammer = Game.ServerStorage.Jackhammer:Clone()
jackhammer.Parent = Game.StarterPack
end

 
MarketplaceService.PromptGamePassPurchaseFinished:Connect(gamepassPurchaseFinished)
1 Like

StarterPack is not a valid member of Game so it will cause an error. I would suggest this(If it will work):

local function gamepassPurchaseFinished(player, gamepassId, wasPurchased)
 local jackhammer = Game.ServerStorage.Jackhammer:Clone()
jackhammer.Parent = player:WaitForChild("StarterPack")
end

 
MarketplaceService.PromptGamePassPurchaseFinished:Connect(gamepassPurchaseFinished)

Why would it be not a member?
Ill try adding a waitforchild.

Is it the Game.StarterPack? If it is then, it is not a member because StarterPack is in a player NOT Game.

GamePass This might help you. Go to the bottom of that page to see the working of the script.

I’m pretty sure this may help:

local MarketplaceService = game:GetService("MarketplaceService")
 
local gamePassID = 0000000  -- Change this to your game pass ID
 
local function Bought(player, purchasedPassID, purchaseSuccess)
 
	if purchaseSuccess == true and purchasedPassID == gamePassID then
        local jackhammer = Game.ServerStorage.Jackhammer:Clone()
        jackhammer.Parent = player.Backpack
	end
end

local giveOnRespawn(player)
   if MarketplaceService:UserOwnsGamePassAsync(player.UserId, gamePassID) then
      local jackhammer = Game.ServerStorage.Jackhammer:Clone()
      jackhammer.Parent = player.Backpack
   end
end
 
game.Players.PlayerAdded:Connect(player)
    player.CharacterAdded:Connect(function(character)
       giveOnRespawn(player)
   end)
end)
MarketplaceService.PromptGamePassPurchaseFinished:Connect(Bought)
2 Likes

Maybe this video can help You : https://www.youtube.com/watch?v=hf3vU3IIkuc

2 Likes

Correct me if I’m wrong but, shouldn’t you connect the function giveOnRespawn when the character has respawned using the CharacterAdded event? This function will only run once the player is in the game. Meaning that it will run only once.

1 Like

Oops-
Sorry, I just forgot that.

2 Likes

It’s ok. We all make mistakes. I just wanted to correct something that I saw was wrong. Sorry If I came off sorta passive aggressive.

2 Likes

Sorry, I’ve been away for a bit. I will test @CluelessAbd’s solution withing the next hour. I will tell you if it works :stuck_out_tongue:

Quick question, where would this go

this errors too, heaps of issues.

1 Like

ServerScriptService as a script.

Why does (The part I mentioned above) error?

1 Like