Soooo I'm kinda lost. I'm trying to have it that once it's clicked, if the player has the gamepass, it turns a button's visibility to true. I got it to prompt the gamepass but this is my first time working with gamepasses, so I'm not sure what to do.
local id = 9581363 script.Parent.MouseButton1Down:Connect(function() game:GetService("MarketplaceService"):PromptGamePassPurchase(game.Players.LocalPlayer,id) end) script.Parent.MouseButton1Click:Connect(function() if game:GetService("MarketplaceService"):PromptGamepassPurchaseFinishd:Connect(function(id) == true then script.Parent.Parent.ChangeMaterial.Visible = false end end)
if anyone could help me it'd be greatly appreciated :)
:UserOwnsGamepassAsync
--- LOCAL SCRIPT local id = 9581363 local MarketPlaceService = game:GetService("MarketplaceService") local Player = game.Players.LocalPlayer function prompt() MarketPlaceService:PromptGamePassPurchase(Player, id) end script.Parent.MouseButton1Click:Connect(prompt) ------------------------------------------- --- SCRIPT, in server script service MarketPlaceService.PromptGamePassPurchaseFinished:Connect(function(player, purchaseid, purchasesucess) if purchasesucess == true and purchaseid == id then player:WaitForChild("PlayerGUI"):FindFirstChild("ChangeMaterial", true).Visible = false -- give the player an advantage, like end end) if MarketPlaceService:UserOwnsGamePassAsync(Player.UserId, id) then print("Player already has the gamepass") Player:WaitForChild("PlayerGUI"):FindFirstChild("ChangeMaterial", true).Visible = false end
You've got a few problems in your script.
First, don't use separate functions when you prompt the player and then deal with what happens after you prompt them.
Second, I'm confused that you set the visibility to false, even though you said that you wanted the button's visibility to be set to true.
Third, PromptGamePassPurchaseFinished
is an event, not a function so you would place a period before it, not a colon. You also misspelled "Finished".
Fourth, you do not need to figure out if the player has the game pass by prompting them. I will first show you the correct way to prompt and find out whether or not the player bought the game pass; and then I will show you how to have the game check if the player already has the game pass without prompting them (which is what I think you wanted).
local id = 9581363 script.Parent.MouseButton1Down:Connect(function() game:GetService("MarketplaceService"):PromptGamePassPurchase(game.Players.LocalPlayer,id) -- prompt player with game pass -- Now this is after they have been prompted and they either hit cancel or purchased the game pass game:GetService("MarketplaceService").PromptGamepassPurchaseFinished:Connect(function(game.Players.LocalPlayer, id, wasPurchased) -- wasPurchased is a bool value which tells you whether or not the player purchased the game pass. So if the player hit cancel, the value is false. If the player buys the game pass, then the value is true. if wasPurchased == true then -- if player bought the game pass script.Parent.Parent.ChangeMaterial.Visible = true else return end end) end)
local id = 9581363 local player = game.Players.LocalPlayer script.Parent.MouseButton1Click:Connect(function() if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, id) then -- UserOwnsGamePassAsync checks if the player has the game pass script.Parent.Parent.Visible = true -- I strongly advise you to reference this in PlayerGui instead of StarterGui because it will not become visible until the player resets else return end end)