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

How Can i Detect If A Player Owns A Gamepass On A Gui Click?

Asked by 3 years ago
Edited 3 years ago

i have tried may methods but it keeps saying: unable to cast value to object, here is my code:

local passId = 13118751 -- change this to your game pass ID.
local player = game.Players.LocalPlayer
player.PlayerGui:WaitForChild("AdminGUI")
local current = player.PlayerGui.AdminGUI

script.Parent.MouseButton1Click:Connect(function()
    if game:GetService("MarketplaceService"):PlayerOwnsAsset(player, passId) then 
        current.Enabled = true
    else
        game:GetService("MarketplaceService"):PromptGamePassPurchase(game.Players.LocalPlayer, passId)
    end
end)

Answer this question