Help my with this GUI script

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)

connect needs to have a capital “C”

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)
3 Likes

Thank you very much! It works exactly like I wanted it to, I’ve tried it again a few times yesterday but it never worked… so yeah thank you again!

1 Like