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).
- When the player clicks on the GUI, they get prompted.
local id = 9581363
script.Parent.MouseButton1Down:Connect(function()
game:GetService("MarketplaceService"):PromptGamePassPurchase(game.Players.LocalPlayer,id)
game:GetService("MarketplaceService").PromptGamepassPurchaseFinished:Connect(function(game.Players.LocalPlayer, id, wasPurchased)
if wasPurchased == true then
script.Parent.Parent.ChangeMaterial.Visible = true
else
return
end
end)
end)
- When the player clicks on the GUI, the game will check to see if they have the game pass (I think this is what you want).
local id = 9581363
local player = game.Players.LocalPlayer
script.Parent.MouseButton1Click:Connect(function()
if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, id) then
script.Parent.Parent.Visible = true
else
return
end
end)
1 comment
You misspelt "finished" in line 8.