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

MarketPlaceService won't work? [UNANSWERED] [PLEASE ANSWER]

Asked by 10 years ago

Ok, just to let you know this is in a LOCAL SCRIPT. Also, this is in a TextButton in a Surface GUI. There are four different copies of the same surface gui. If you don t understand what I mean about four different copies, click here Accaully, you might want to click that link because It explains the script a whole lot better. Oh, yeah! I have a leaderboard for this script too.

Here is the script:

local buyButton = script.Parent
local productId = 19201593 
local mps = game:GetService"MarketplaceService"

function getPlayerById(id)
for i,v in pairs(game.Players:GetPlayers()) do
if v.userId == id then
return v
end
end
end

buyButton.MouseButton1Click:connect(function()
mps:PromptProductPurchase(game.Players.LocalPlayer, productId)
end)

mps.ProcessReceipt = function(info)
local plr = getPlayerById(info.PlayerId)
if plr and plr:FindFirstChild"leaderstats" and plr.leaderstats:FindFirstChild"Credits" then
plr.leaderstats.Points.Value = plr.leaderstats.Credits.Value + 10000 --awards 10,000 credits when the player buys dev product
end
end

Please give me a answer! Thank you so much!!

1 answer

Log in to vote
1
Answered by
Xetrax 85
10 years ago

The firs thing I noticed is that your local mps = game:GetService"MarketplaceService" line and your other lines: plr:FindFirstChild"leaderstats", plr.leaderstats:FindFirstChild"Credits" arn't structured correctly for the script to work, make sure when you do :FindFirstChild() and :GetService() that you actually have the () when you tyoe them, typing what you have put will confuse the script, because you're not specifying what it has to do; try this:

local buyButton = script.Parent
local productId = 19201593
local mps = game:GetService("MarketplaceService")   --adding the () specifies what you want the script to do, as far as I understand it.

function getPlayerById(id)
for i,v in pairs(game.Players:GetPlayers()) do
if v.userId == id then
return v
end
end
end

buyButton.MouseButton1Click:connect(function()
mps:PromptProductPurchase(game.Players.LocalPlayer, productId)
end)

mps.ProcessReceipt = function(info)
local plr = getPlayerById(info.PlayerId)
if plr and plr:FindFirstChild("leaderstats") and plr.leaderstats:FindFirstChild("Credits") then
plr.leaderstats.Points.Value = plr.leaderstats.Credits.Value + 10000 --awards 10,000 credits when the player buys dev product
end
end

If this doesn't work, then someone else will hopefully answer your question.

0
Woops PyccknnXakep 1225 — 10y
0
lol, We all make mistakes, as you may have noticed, I made a spelling error in my answer... :P Xetrax 85 — 9y
Ad

Answer this question