Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

how do i let the player access the button in the gui only if he has the gamepass?

Asked by 2 years ago

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

0
clarify MarkedTomato 810 — 2y
0
I just want a button to be removed from the player's gui if it has a gamepass NineTailedFox_BR 13 — 2y

1 answer

Log in to vote
0
Answered by 2 years ago
Edited 2 years ago

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:

DevHub: GamePassService

DevHub: MarketplaceService

Ad

Answer this question