How to make a game pass purchase prompt every time a player dies?

Hello. I am wanting to implement into my game a game pass purchase prompt every second/third time a player dies. How can I do this? I have searched thoroughly online and haven’t found a tutorial on this. If anyone knows of a tutorial or can explain to me how I can do this, please do share. Thank you.

Edit: I am just building a basic obby, but want a game pass purchase prompt to appear everytime a player dies 3 times.

Edit: Thinking more about it, I’d like a gui screen to appear and have a “purchase ‘this’ game pass? yes or no?” that would be much less intrusive then a actual like prompt to purchase immediately. I have already created a shop button gui on screen to the side, which works typically as a player pressed the button and a shop appears. But i’d like every 3 times a player dies for the gui to purchase a specific game pass pop up. Hope this makes sense.

Use Humanoid.Died to detect whether the Player has died, depending on how many lives the have (Assuming its a Life System) check if they have less than 1, or exactly 0, if the conditions are true, prompt this gamepass using MarketplaceService:PromptProductPurchase() or MarketplaceService:PromptGamepassPurchase()

2 Likes

Thank you for the prompt reply… There is no life system. I am just building a basic obby, but want a game pass purchase prompt every second or third time a player dies.

1 Like

So it would basically be like a life system, all you are doing is subtracting a Value, and when that value reaches 0 or less than 1, prompt the gamepass.

Each time the player dies you could count it and once it reaches 2 or 3, prompt the pass.

local timesDied = 0
local plr = game:GetService("Players").LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local Humanoid =  chat.Humanoid

Humanoid.Died:Connect(function())
  timesDied += 1
  if timesDied == 2 then 
     --prompt pass
  end
end)

Something like thia perhaps, put it in a local script in StarterPlayerScripts.

1 Like

Thank you. I would actually like the prompt to be a gui which say’s something along the lines of: purchase this game pass? [yes] or [no]. and when a player clicks yes button, then the game pass purchase appears on screen, if the player clicks the no button, the gui just disappears.

and ideally I would like it to switch to a different game pass every time. If you know what I mean. So it’s not just the same game pass every prompt.

psst…

local timesDied = 0
local plr = game:GetService("Players").LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local Humanoid =  chat.Humanoid

Humanoid.Died:Connect(function())
  timesDied += 1
  if timesDied == 2 then 
     --prompt pass
  end
end)

plr.CharacterAdded:Connect(function()
     char = plr.Character 
     Humanoid =  chat.Humanoid
end)

We need this function because when a New character is added, a new humanoid is made, making the Humanoid Variable out of date mentioning a instance not used anymore.


This should work:

local ScreenGui = nil --Repalce with pathway
local YesButton = nil --Repalce with pathway
local NoButton = nil --Repalce with pathway
local Gamepasses = {12345, 6789, 1234567890, } --All gamepass IDs in here



local timesDied = 0
local plr = game:GetService("Players").LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local Humanoid =  chat.Humanoid


NoButton.MouseButton1Click:Connect(function()
   ScreenGui.Enable = false
end)

YesButton.MouseButton1Click:Connect(function()
   game:GetService("MarketplaceService"):PromptGamePassPurchase(plr, Gamepasses[math.random(1, #Gamepasses)] )
   ScreenGui.Enable = false
end)


Humanoid.Died:Connect(function())
  timesDied += 1
  if timesDied >= math.random(2, 3) then 
     timesDied = 0
     ScreenGui.Enable = true
  end
end)

plr.CharacterAdded:Connect(function()
     char = plr.Character 
     Humanoid =  chat.Humanoid
end)

1 Like