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

Scripting a "purchase gamepass" button?

Asked by 4 years ago

Hello! I've made a gui to purchase a gamepass. The button is scripted with the following code:

local plr = game.Players.LocalPlayer
local button = script.Parent
local MarketplaceService = game:GetService("MarketplaceService")

script.Parent.MouseButton1Click:Connect(function()
    MarketplaceService:PromptGamePassPurchase(plr, 3312863)
end)

It fails, and the output text is: MarketplaceService:PromptGamePassPurchase() player should be of type Player, but is of type nil Any help?

0
Is this a server script or a localscript? You can only use localplayer in a localscript. royaltoe 5144 — 4y

1 answer

Log in to vote
0
Answered by
DrShockz 233 Moderation Voter
4 years ago

You can only use LocalPlayer in a local script. So replace this with a local script and it should work like a charm! (btw change mousebtutton1click to mousebutton1down it just makes it feel more clicky)

0
Alright, thank you! Robloximario952 18 — 4y
Ad

Answer this question