Need help with script! For gamepass function

Hello readers and scripters I need help making a button only work if the player owns a pass like a script will work or not work depending on if the player has the gamepass!

I have tried many ways but I am still new to scripting and I would love help!!

local CarParams = game.ReplicatedStorage:WaitForChild(“GetCarParams”):InvokeServer(script.Parent.Name)

local CarImage = script.Parent.CarImage

local ShowPurchaseFrame = script.Parent.Parent.Parent.Parent.ShowPurchaseFrame

script.Parent.CarName.Text = CarParams.Name

script.Parent.Cost.Text = CarParams.Cost

script.Parent.MouseButton1Down:Connect(function()

ShowPurchaseFrame:Fire(CarParams.Name, CarParams.Cost, CarParams.Power, script.Parent.CarImage)

end)

Local Script:

local Player = game.Players.LocalPlayer

local MarketplaceService = game:GetService("MarketplaceService")

local gamepassId = 0 -- your gamepass ID here

local CarParams = game.ReplicatedStorage:WaitForChild('GetCarParams'):InvokeServer(script.Parent.Name)

local CarImage = script.Parent.CarImage

local ShowPurchaseFrame = script.Parent.Parent.Parent.Parent.ShowPurchaseFrame

script.Parent.CarName.Text = CarParams.Name

script.Parent.Cost.Text = CarParams.Cost

script.Parent.MouseButton1Down:Connect(function()

if MarketplaceService:UserOwnsGamePassAsync(Player.UserId, gamepassId) then

ShowPurchaseFrame:Fire(CarParams.Name, CarParams.Cost, CarParams.Power, script.Parent.CarImage)

end

end)
1 Like

Thankyou adudu21 I will try that!

1 Like