The if statements are a bit inefficient and the Ids table is useless, instead you could have a dictionary with the IDs as the keys and the number of points as the values and just add the value onto the player’s points by doing player.leaderstats.Points.Value += points[productInfo.ProductId]
Result:
local MarketPlaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local pointQuantities = {
[1034505260] = 50,
[1034505524] = 110,
[1034505858] = 250,
[1034506135] = 600,
[1034506492] = 1500,
}
local function productHandler(productInfo)
local Player = Players:GetPlayerByUserId(productInfo.PlayerId)
if not Player then return Enum.ProductPurchaseDecision.NotProcessedYet
end
Player.leaderstats.Points.Value += pointQuantities[productInfo.ProductId]
return Enum.ProductPurchaseDecision.PurchaseGranted
end
MarketPlaceService.ProcessReceipt = productHandler
This makes it a lot cleaner cause you can handle entire products with different functionality just by adding a function to that specific id. So say you wanted to handle more than just adding points creating functions for each individual would benefit.
You could also make a handler to detect if the id in question are to be given by points as well. This could make it a lot easier so it’s not a bunch of copy and paste and change the points given which can always get messy as we all know.
Then you’re just taking more time to do so. That’s how it used to be done but I’ve gotten attached to the compound operators already. Can easily just do Player.leaderstats.Points.Value += 110
This line of code is indexing pointQuantities with the ProductId, which will return the corresponding number of points to be given(pointQuantities[1034505260] returns 50). One of the main advantages with dictionaries is that you’re able to sort of connect two values and access one with the other.