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

Addings assets to players through MarketPlaceService?

Asked by
rsh2 2
6 years ago

I am using a local script and tried to access MarketPlaceService, but it continues to say error. Before it stated that there was an unknown player, which i attempted to fix by adding the .Parent 7 times, until it reached workspace, but it still seems to be giving errors. The following is the one im encountering:

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

I don't understand. Please help?

local purchase = script.Parent.Parent:WaitForChild("PurchaseButton")

purchase.MouseButton1Click:connect(function (player)
    local Id = script.Parent.Text -- typed in ID
    print("id taken")

game:GetService("MarketplaceService"):PromptPurchase(script.Parent.Parent.Parent.Pare       nt.Parent.Parent.Parent:GetChildren(player),Id)
end)

I'm afraid I might have to use script instead of LocalScript, which is what i'm currently using, but i have no idea. Any thoughts?

1 answer

Log in to vote
0
Answered by
xPolarium 1388 Moderation Voter
6 years ago
Edited 6 years ago

The problem isn't because it's a local script. It's because :PromptPurchase() needs the Player object, not the character, otherwise you get that error.

Since it's the local player clicking their local purchase button then define the LocalPlayer at the top.

local player = game.Players.LocalPlayer
local purchase = script.Parent.Parent:WaitForChild("PurchaseButton")

purchase.MouseButton1Click:connect(function()
    local Id = script.Parent.Text -- typed in ID
    print("id taken")

game:GetService("MarketplaceService"):PromptPurchase(player, Id)
end)

0
in addition, I'm guessing you're prompting developer products. Might want to use "PromptProductPurchase" instead, "PromtPurchase" is for GamePassService. Astralyst 389 — 6y
0
Thank you so much. I left PromptPurchase because it was meant for the roblox catalog, and it did work. The problem for me was calling on Player incorrectly. I guess these tiny things make a huge ripple effect! rsh2 2 — 6y
Ad

Answer this question