Hey guys! I’m currently struggeling with a GUI script, I want to achieve that it only executes the script/shows the GUI when a Gamepass is owned.
I’ve already tried doing the whole game:GetService(“MarketplaceService”):PlayerOwnsAsset(player, gamePassID) thing but it then marked the player red. I’m pretty new to scripting so I hope you guys can help me!
Here’s the script:
function boop(Player)
if not Player.PlayerGui:FindFirstChild("Gui") then
local gui = script.Gui:clone()
gui.Parent = Player.PlayerGui
end
end
script.Parent.ClickDetector.MouseClick:connect(boop)
There’s actually a function that’s called PromptGamePassPurchase, and an event called PromptGamePassPurchaseFinished, inside the MarketPlaceService; you can refer to this post for more info (Which you can replace with your GUI when you want) , but this should do it:
local MarketService = game:GetService("MarketPlaceService")
local GamepassID = 00000 --Make sure to change that with your ID
function boop(Player)
if MarketService:UserOwnsGamePassAsync(Player.UserId, GamepassID) then
local GuiClone = script.Gui:Clone()
Gui.Parent = Player.PlayerGui
else
MarketService:PromptGamePassPurchase(Player, GamepassID)
end
MarketService.PromptGamePassPurchaseFinished:Connect(function(Player, GamepassID, PurchaseSuccess)
if PurchaseSuccess == true then
local GuiClone = script.Gui:Clone()
Gui.Parent = Player.PlayerGui
end
end)
end
script.Parent.ClickDetector.MouseClick:Connect(boop)