Hello, I am trying to make it so a action is only performed if a game pass is owned and if it is not owned a purchase is promoted (this works). However, while doing a test purchase in studio and tapping the button again it only prompts me to buy it again. The intended behavior is that you get promoted once and (assuming you buy) it you can tap the button again and the menu will open.
local player = game.Players.LocalPlayer
script.Parent.MouseButton1Click:Connect(function()
if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, 9043066) then
script.Parent.Parent.Parent.Colors.Visible = false
script.Parent.Parent.Parent.FaceList.Visible = false
script.Parent.Parent.Parent.HatsList.Visible = false
script.Parent.Parent.Parent.ShirtList.Visible = false
script.Parent.Parent.Parent.PantsList.Visible = false
script.Parent.Parent.Parent.Egg2008.Visible = false
script.Parent.Parent.Parent.Egg2010.Visible = true
script.Parent.Parent.Parent.SpecialMenu.Visible = false
else
game:GetService("MarketplaceService"):PromptGamePassPurchase(player, 9043066)
end
end
)
I hope this wasn’t to confusing and this should be my last thread about game passes!
Just so I understand this correctly. You’re wanting to make a unlock button gamepass? Until the player own the gamepass their not able to press on the button? But when they do they can hen open it?
I don’t understand what you are talking about. I am just trying to make it so that the menu will be able to be opened after you buy the game pass without the need to rejoin
Okay, what I would do in this case would be as follows: 1. I would integrate that player owning the gamepass in the playerAdded function. 2. Create a boolvalue and parent it to the player (true or false) 3. Then When you check if the player owns the gamepass when they joined (if they own it, tick the boolvalue to true) 3. If they don’t then thats fine, prompt it for them and if they purchase it make the boolvalue equal to true 4. Where your GUI box is, when you use MouseButton1Down, make an if statement checking if the players boolvalue is true and if it is then what you want it to do.
I mean you create a true or false variable, when the player joins the game check if the player owns it. If they do check the true or false varaible to true. Then where you have the script.Parent.MouseButton1Click, make a if plr.something.HasPass.Value == true then ur stuff, else promt purchase
I know that but that only happens when the game loads. This would mean the player would have to rejoin to use the game pass. Is there a way to detect if the purchases was successful and set the value to true if it was?
Yes there is. Here is an example, as you can access the prompt on the server:
local marketplace = game:GetService("MarketplaceService")
local sS = game:GetService("ServerStorage")
local gamePassOneID = 0000000
local function onPromptGamePassPurchaseFinished(player, purchasedPassID, purchaseSuccess)
if purchaseSuccess == true and purchasedPassID == gamePassOneID then
sS.playerStats[player.Name].gamePasses.bamboS.Value = true --playerStats is a folder in ServerStorage that stores the plrs data
end
end
marketplace.PromptGamePassPurchaseFinished:Connect(onPromptGamePassPurchaseFinished)
This is an example of what happens after you prompt the purchase on a local script.
Alrighty! How would I implement this into my script.
local player = game.Players.LocalPlayer
if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, 9043064) then
script.Parent.Text = "Egg Hunt 2008"
end
local marketplace = game:GetService("MarketplaceService")
local gamePassOneID = 9043064
local function onPromptGamePassPurchaseFinished(player, purchasedPassID, purchaseSuccess)
if purchaseSuccess == true and purchasedPassID == gamePassOneID then
player.egg08.Value = true
end
end
marketplace.PromptGamePassPurchaseFinished:Connect(onPromptGamePassPurchaseFinished)
script.Parent.MouseButton1Click:Connect(function()
if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, 9043064) then
game.Players.LocalPlayer.egg08.Value = true
end
if game.Players.LocalPlayer.egg08.Value == true then
script.Parent.Parent.Parent.Colors.Visible = false
script.Parent.Parent.Parent.FaceList.Visible = false
script.Parent.Parent.Parent.HatsList.Visible = false
script.Parent.Parent.Parent.ShirtList.Visible = false
script.Parent.Parent.Parent.PantsList.Visible = false
script.Parent.Parent.Parent.Egg2008.Visible = true
script.Parent.Parent.Parent.Egg2010.Visible = false
script.Parent.Parent.Parent.SpecialMenu.Visible = false
else
onPromptGamePassPurchaseFinished(player, purchasedPassID, purchaseSuccess)
game:GetService("MarketplaceService"):PromptGamePassPurchase(player, 9043064)
end
end
)
Please note that I had to change the server storage to be in player. My data is stored in the player.
local player = game.Players.LocalPlayer
if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, 9043064) then
script.Parent.Text = "Egg Hunt 2008"
end
local marketplace = game:GetService("MarketplaceService")
local gamePassOneID = 9043064
local function onPromptGamePassPurchaseFinished(player, purchasedPassID, purchaseSuccess)
if purchaseSuccess == true and purchasedPassID == gamePassOneID then
player.egg08.Value = true
end
end
marketplace.PromptGamePassPurchaseFinished:Connect(onPromptGamePassPurchaseFinished)
script.Parent.MouseButton1Click:Connect(function()
if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, 9043064) then
game.Players.LocalPlayer.egg08.Value = true
end
if game.Players.LocalPlayer.egg08.Value == true then
script.Parent.Parent.Parent.Colors.Visible = false
script.Parent.Parent.Parent.FaceList.Visible = false
script.Parent.Parent.Parent.HatsList.Visible = false
script.Parent.Parent.Parent.ShirtList.Visible = false
script.Parent.Parent.Parent.PantsList.Visible = false
script.Parent.Parent.Parent.Egg2008.Visible = true
script.Parent.Parent.Parent.Egg2010.Visible = false
script.Parent.Parent.Parent.SpecialMenu.Visible = false
else
game:GetService("MarketplaceService"):PromptGamePassPurchase(player, 9043064)
local function onPromptGamePassPurchaseFinished(player, purchasedPassID, purchaseSuccess)
if purchaseSuccess == true and purchasedPassID == gamePassOneID then
player.egg08.Value = true
script.Parent.Text = "Egg Hunt 2008"
end
end
end
end
)
If you do not own the game pass it prompts you and if you buy it then you can get into the menu, like it should.
local player = game.Players.LocalPlayer
if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, 9043066) then
script.Parent.Text = "Egg Hunt 2010"
end
local marketplace = game:GetService("MarketplaceService")
local gamePassOneID = 9043066
local function onPromptGamePassPurchaseFinished(player, purchasedPassID, purchaseSuccess)
if purchaseSuccess == true and purchasedPassID == gamePassOneID then
player.egg10.Value = true
end
end
script.Parent.MouseButton1Click:Connect(function()
if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, 9043066) then
game.Players.LocalPlayer.egg10.Value = true
end
if game.Players.LocalPlayer.egg10.Value == true then
script.Parent.Parent.Parent.Colors.Visible = false
script.Parent.Parent.Parent.FaceList.Visible = false
script.Parent.Parent.Parent.HatsList.Visible = false
script.Parent.Parent.Parent.ShirtList.Visible = false
script.Parent.Parent.Parent.PantsList.Visible = false
script.Parent.Parent.Parent.Egg2008.Visible = false
script.Parent.Parent.Parent.Egg2010.Visible = true
script.Parent.Parent.Parent.SpecialMenu.Visible = false
else
game:GetService("MarketplaceService"):PromptGamePassPurchase(player, 9043066)
local function onPromptGamePassPurchaseFinished(player, purchasedPassID, purchaseSuccess)
if purchaseSuccess == true and purchasedPassID == gamePassOneID then
player.egg10.Value = true
script.Parent.Text = "Egg Hunt 2010"
end
end
end
end
)
This however, does not work. if you buy the game pass it just prompts you again.
Edit: I always figure it out after posting -_-
I forgot “marketplace.PromptGamePassPurchaseFinished:Connect(onPromptGamePassPurchaseFinished)”