Could someone help me I wanted to make a gamepass button I made the following but I created a button on top of the button that I want the player to only have access if he has the gamepass if the player doesn't have a picture of a padlock look below my script
local test = script.Parent local player = game.Players.LocalPlayer local id = 17126951 if game:GetService("GamePassService"):PlayerHasPass(player, id) then test:Destroy() end
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:
-- Using MarketplaceService 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 -- // If player doesn't have the gamepass 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 -- // If player doesn't have gamepass test:Destroy() end
Otherwise, if you want to check if they do have the gamepass, then you can just erase not.
Sources: