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

MarketplaceService:PromptProductPurchase() error, how can I fix this?

Asked by 3 years ago

So, basically I decided to check out a Roblox document about marketplaceservice:promptpurchase. I got this weird error stating:

MarketplaceService:PromptProductPurchase() player should be of type Player, but is of type Players

If it has to be a local script, I cant do that since proximity prompt doesn't work for local scripts.

Script:

local ProximityPrompt = script.Parent
local player = game:getService("Players")
local productId = 1164763860

ProximityPrompt.Triggered:Connect(function()
    game:GetService("MarketplaceService"):PromptProductPurchase(player, productId)
    if productId == 1164763860 then
        print("Test")

    elseif productId == 1164763860 then
        print("Test")

    end

end)

3 answers

Log in to vote
0
Answered by 3 years ago

You're trying to prompt the whole players service to buy your product. You should instead prompt a player, or run a for loop through game.Players:GetPlayers() to prompt everyone.

Ad
Log in to vote
0
Answered by 3 years ago
Edited 3 years ago
local ProximityPrompt = script.Parent
local productId = 1164763860

ProximityPrompt.Triggered:Connect(function(player) -- player that activated it.
    game:GetService("MarketplaceService"):PromptProductPurchase(player, productId)

    -- deleted rest of code because it does nothing hehe
end)
Log in to vote
0
Answered by
Xapelize 2658 Moderation Voter Community Moderator
3 years ago
Edited 3 years ago

You should rather try using a ClickDetector function in your brick so it can easily accessed from LocalScript. Otherwise the prompt will fire in everyone becaues you are using :GetPlayers which is all the players

if you want to use touched event or want to get a pro move then use remote event, using :FireClient and from the localscript get the client using :OnClientEvent

Also player is a service, not a player, you should use LocalScript to access the player in Players service or get them using a player added event and get the player parameter

if you dont know what i mean just ask me go ahead

0
im lazy to be formal but if you understand then do anything if you want Xapelize 2658 — 3y

Answer this question