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

I need help with Prompt Service in a Server Script?

Please help! (This is a server script)

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

Error: MarketPlaceService:PromptPurchase() player should be of type, but type is nil

2 comments

0

is this a local script?

0

What is the script's parent?

2 answers

Question: Prompt Purchase does not prompt.

The reason why is because there's no parameters with MouseButton1Click. That's why player is returning nil, since it doesn't exist.

You'll have to use another method of grabbing the player, such as RemoteEvents.

ALSO: connect is deprecated. Please use Connect instead.

3 comments

1

If the parent of the script is a click detector, then there is a player argument passed when the MouseButton1Click event fires.

0

Thank you!

0

@Mythical he was using a guibutton. There's no MouseButton1Click on ClickDetector's

###Since you were working with GUIs, you should not be using a server script. Use a LocalScript, use LocalPlayer, and problem solved. Always remember to use Local Scripts when working with GUIs.

local player = game.Players.LocalPlayer -- this only works in localscripts

script.Parent.MouseButton1Click:Connect(function()
    game:GetService("MarketplaceService"):PromptPurchase(player, 2286611813) 
    -- if you want to prompt a game pass, use :PromptGamePassPurchase
end)

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