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

Why wont these dev products work?

Asked by 10 years ago

I am trying to make a GUI that sells dev products. In this case, i am trying to make it give you a certain amount of Credits (250) after purchasing a dev product. I can't seem to find the problem here... Can anyone help?

01-- setup local variables
02local MarketplaceService = Game:GetService("MarketplaceService")
03local ds = game:GetService("DataStoreService"):GetDataStore("PurchaseHistory")
04local productId = 20768662
05 
06-- define function that will be called when purchase finished
07MarketplaceService.ProcessReceipt = function(receiptInfo)
08 
09    -- find the player based on the PlayerId in receiptInfo
10    for i, player in ipairs(game.Players:GetChildren()) do
11        if player.userId == receiptInfo.PlayerId then
12 
13            -- check which product was purchased
14            if receiptInfo.ProductId == productId then
15                --handle purchase. In this case we are highering the player's Credits value        
View all 22 lines...
0
What's the error message? CardboardRocks 215 — 10y
0
The error message is: attempt to index global 'plr' (a nil value) omrisoso 10 — 10y

3 answers

Log in to vote
3
Answered by
Relatch 550 Moderation Voter
10 years ago

You didn't define player.

Whenever you see that kind of error, remember that it means you have to define it. It doesn't know what plr is

Ad
Log in to vote
3
Answered by 10 years ago

Here put this code in a script then put the script in StarterPack:

01local MarketplaceService = Game:GetService("MarketplaceService")
02local ds = game:GetService("DataStoreService"):GetDataStore("PurchaseHistory")
03 
04CASHID = 00000000 -- Put the Developer Product ID here and erase the 0's
05 
06MarketplaceService.ProcessReceipt = function(receiptInfo)
07    local playerProductKey = "player_" .. receiptInfo.PlayerId .. "_product_" .. receiptInfo.ProductId
08    local numberBought = ds:IncrementAsync(playerProductKey, 1)
09    for i,v in pairs (game.Players:GetChildren()) do
10        if v.userId == receiptInfo.PlayerId then
11            if receiptInfo.ProductId == CASHID then
12 
13 
14                lds = v:FindFirstChild("leaderstats")
15                if lds ~= nil then
View all 25 lines...

Don't forget to say this answered you and give it a thumbs up because I am working for a good reputation!

Log in to vote
-1
Answered by
M39a9am3R 3210 Moderation Voter Community Moderator
10 years ago

On line 16 change plr to player. Plr is nil to the script since it was never defined.

And add to line 19 or else the player will get credits on entry. return Enum.ProductPurchaseDecision.PurchaseGranted

Please refrain from reposting this question.

Any errors, just comment on this answer.


01-- setup local variables
02local MarketplaceService = Game:GetService("MarketplaceService")
03local ds = game:GetService("DataStoreService"):GetDataStore("PurchaseHistory")
04local productId = 20768662
05 
06-- define function that will be called when purchase finished
07MarketplaceService.ProcessReceipt = function(receiptInfo)
08 
09    -- find the player based on the PlayerId in receiptInfo
10    for i, player in ipairs(game.Players:GetChildren()) do
11        if player.userId == receiptInfo.PlayerId then
12 
13            -- check which product was purchased
14            if receiptInfo.ProductId == productId then
15                --handle purchase. In this case we are highering the player's Credits value        
View all 23 lines...
0
Im sorry, but i am not that advanced at scripting... Can you please show me an example of what u meant to put at line 19? omrisoso 10 — 10y
0
This still doesnt work... can you please rephrase? omrisoso 10 — 10y
0
Still doesnt work........... omrisoso 10 — 10y
0
Oh, and it still says the same error omrisoso 10 — 10y
0
Are you using the script in my answer? It shouldn't be giving you a error. If it does, then post the line it is on (should be in blue text). M39a9am3R 3210 — 10y

Answer this question