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

MarketplaceService:PromptGamePassPurchase() player should be of type Player, but is of type nil?

I tried to make a gamepass prompt, but when I clicked the button I got an error on line 5.

"MarketplaceService:PromptGamePassPurchase() player should be of type Player, but is of type nil"

This is the code (local script):

local MarketplaceService = game:GetService("MarketplaceService")
local gamepassId = 16463231

script.Parent.MouseButton1Click:Connect(function(player)
	MarketplaceService:PromptGamePassPurchase(player, gamepassId)
end)

Can someone please help me? Thanks!

1 answer

✓ Accepted answer

I think it would be better to use a remote event to fire it and prompt the purchase on the server. Here is how you would do that:

local remoteevent = game.Replicatedstorage.Remoteevent -- change "remote event" to whatever you call your remote event

script.Parent.MouseButton1Click:Connect(function()
       remoteevent:FireServer()
end)

Then on the server:

local remoteevent = game.Replicatedstorage.Remoteevent
local MarketplaceService = game:GetService("MarketplaceService")

local gamepassId = 16463231

remoteevent.OnServerEvent:Connect(function(player) -- you can state player here because a fire server automatically includes the player as the first argument
     MarketplaceService:PromtGamePassPurchse(player, gamepassId)
end)


I hope this has helped :)

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