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

I need help with Prompt Service in a Server Script?

Asked by 5 years ago
Edited 5 years ago

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

0
is this a local script? awesomeipod 607 — 5y
0
What is the script's parent? MythicalShade 420 — 5y

2 answers

Log in to vote
1
Answered by
green271 635 Moderation Voter
5 years ago
Edited 5 years ago

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.

1
If the parent of the script is a click detector, then there is a player argument passed when the MouseButton1Click event fires. MythicalShade 420 — 5y
0
Thank you! retrobricks 162 — 5y
0
@Mythical he was using a guibutton. There's no MouseButton1Click on ClickDetector's green271 635 — 5y
Ad
Log in to vote
1
Answered by 5 years ago

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)

Answer this question