Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Scripting a "purchase gamepass" button?

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?

1 comment

0

Is this a server script or a localscript? You can only use localplayer in a localscript.

1 answer

✓ Accepted answer

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)

1 comment

0

Alright, thank you!

This discussion is preserved as it was. New answers, comments, and votes are closed.