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?
-- setup local variables
local MarketplaceService = Game:GetService("MarketplaceService")
local ds = game:GetService("DataStoreService"):GetDataStore("PurchaseHistory")
local productId = 20768662
-- define function that will be called when purchase finished
MarketplaceService.ProcessReceipt = function(receiptInfo)
-- find the player based on the PlayerId in receiptInfo
for i, player in ipairs(game.Players:GetChildren()) do
if player.userId == receiptInfo.PlayerId then
-- check which product was purchased
if receiptInfo.ProductId == productId then
--handle purchase. In this case we are highering the player's Credits value
plr.leaderstats.Credits.Value = plr.leaderstats.Credits.Value + 250
-- more feedback for the player.
game.Workspace.DisplayScreen.SurfaceGui.TextBox.Text = player.Name .. " has purchased more credits."
end
end
end
end

2 comments
What's the error message?
The error message is: attempt to index global 'plr' (a nil value)