Personally, I prefer MarketplaceService, which has more features. GamePassService is basically the legacy version of MarketplaceService., but it doesn't have as many features as MarketplaceService.
Anyway, here's your code:
local Market = game:GetService("MarketplaceService")
local test = script.Parent
local player = game.Players.LocalPlayer
local id = 17126951
local ownGP = false
pcall(function()
ownGP = Market:UserOwnGamepassAsync(id, player.UserId)
end)
task.wait()
if not ownGP then
test:Destroy()
end
Looking at your code, it should work fine. Just on the 5th line, you're checking if the player has the gamepass, therefore executing the rest of the script. You should use the function not:
local test = script.Parent
local player = game.Players.LocalPlayer
local id = 17126951
if not game:GetService("GamePassService"):PlayerHasPass(player, id) then
test:Destroy()
end
Otherwise, if you want to check if they do have the gamepass, then you can just erase not.
Sources:
DevHub: GamePassService
DevHub: MarketplaceService
2 comments
clarify
I just want a button to be removed from the player's gui if it has a gamepass