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

Inside a TextButton: MarketplaceService:PromptPurchase()?

Asked by 6 years ago

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

Hello, I am trying to make it to where I can click on my GUI and click the textbutton and the game will prompt me to buy a GamePass. But I receive the error above. How do I go about this? The gui is in the Starter pack and it is in a script not a LocalScript.

local id = 0

function onClick()
script.Parent.MouseButton1Click:connect(function(player)
    game:GetService("MarketplaceService"):PromptPurchase(player, id)
end )
end

script.Parent.MouseButton1Click:connect(onClick)

1 answer

Log in to vote
0
Answered by
cabbler 1942 Moderation Voter
6 years ago
Edited 6 years ago

Mousebutton1Click does not give a player parameter. I think you were confused with ClickDetectors.

This should be in a LocalScript because Gui is client-side.

Once in a LocalScript you can use game.Players.LocalPlayer

Ad

Answer this question