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

Error in MarketplaceService:PromptPurchase()?

Asked by
GShocked 150
9 years ago

I have following Script, which is placed under a ScreenGui in StarterGui. It is supposed to tell a player to buy a T-Shirt forever until they do, unless they are on the ExemptPlayers list.

local AccessShirt = 317838472 --ID of your group's access shirt 
local Player = game.Players.LocalPlayer
local ExemptPlayers = {'GShocked','TCAPI'} --Any players you choose to be exempt of payment
local PlayerExempt = false

for i = 1, #ExemptPlayers do
    if Player == ExemptPlayers[i] then
        PlayerExempt = true
        print("Exempt player joined!")
    end
end

repeat
    game:GetService('MarketplaceService'):PromptPurchase(Player, AccessShirt)
    print("Player hasn't bought")
    wait(1)
until PlayerExempt == true or game:GetService("MarketplaceService"):PlayerOwnsAsset(Player, AccessShirt) == true

This, however, returns the following error:

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

Fixed Code:

local AccessShirt = 317838472 --ID of your group's access shirt 
local Player = game.Players.LocalPlayer
local ExemptPlayers = {'GShocked','TCAPI','MushyLesx'} --Any players you choose to be exempt of payment
local PlayerExempt = false
local Purchased = false

for i = 1, #ExemptPlayers do
    if Player.Name == ExemptPlayers[i] then
        PlayerExempt = true
        print("Exempt player joined!")
    end
end

script.Parent.MouseButton1Click:connect(function()
    game:GetService("MarketplaceService"):PromptProductPurchase(Player, AccessShirt)
end)

while Purchased == false do
    if PlayerExempt == true or game:GetService("MarketplaceService"):PlayerOwnsAsset(Player, AccessShirt) == true then
        script.Parent.Parent:Destroy() --Destroy the ScreenGui blocking you from entering
        Purchased = true
    else
        print("Player canceled purchase.")
    end
end

1 answer

Log in to vote
1
Answered by
peely09 15
9 years ago

First of all your exemption system won't work because on line 7 you're trying to compare a string value - the name of exempt players in your table, with the player (rather than his/her name) It should read (if Player.Name == ExemptPlayers[i])

Also, is this code being run from a LocalScript? If not 'game.Players.LocalPlayer' simply won't work

Finally, you don't seem to be changing the value of PlayerExempt if the shirt is found among their assets, so this would loop indefinitely.

0
Thanks, I already fixed my problems but you perfectly outlined them. GShocked 150 — 9y
Ad

Answer this question