I am trying to make it so that when you buy a developer product you get 10000 points but it just gives me an error
The script is inside ServerScriptService:
local marketPlaceService = game:GetService("MarketplaceService")
local players = game:GetService("Players")
local productId = 1233194930
local function processReceipt(recieptInfo)
local player = players:GetPlayerByUserId(recieptInfo.PlayerId)
if not player then
-- Player probably left
-- If they come back this will be processed again
return Enum.ProductPurchaseDecision.NotProcessedYet
end
if player then
-- What do you want the dev product to do?
local leaderstats = game.Players.LocalPlayer.leaderstats.Points
leaderstats.Value += 10000
end
end
marketPlaceService.ProcessReceipt = processReceipt
The error:
19:37:12.396 ServerScriptService.PointsDevProduct:16: attempt to index nil with 'leaderstats' - Server - PointsDevProduct:16
19:37:12.396 Stack Begin - Studio
19:37:12.396 Script 'ServerScriptService.PointsDevProduct', Line 16 - function processReceipt - Studio - PointsDevProduct:16
19:37:12.396 Stack End - Studio
local marketPlaceService = game:GetService("MarketplaceService")
local players = game:GetService("Players")
local productId = 1233194930
local function processReceipt(recieptInfo)
local player = players:GetPlayerByUserId(recieptInfo.PlayerId)
if not player then
-- Player probably left
-- If they come back this will be processed again
return Enum.ProductPurchaseDecision.NotProcessedYet
end
if player then
-- What do you want the dev product to do?
local leaderstats = player.leaderstats.Points
leaderstats.Value += 10000
end
end
marketPlaceService.ProcessReceipt = processReceipt
You need to make the dev product marked successful
`
if player then
– What do you want the dev product to do?
local leaderstats = game.Players.LocalPlayer.leaderstats.Points
leaderstats.Value += 10000
return Enum.ProductPurchaseDecision.PurchaseGranted
end
you can’t use game.Players.LocalPlayer in a Server sided script. That only works in Local Scripts.
So you need to use player in place of game.Players.LocalPlayer.