Hey, so i was thinking on ways to make my code cleaner / easier to understand or look nicer
if you have any tips please leave a comment
local MarketplaceService = game:GetService("MarketplaceService")
local function processReceipt(receiptInfo)
local player = game:GetService("Players"):GetPlayerByUserId(receiptInfo.PlayerId)
if not player then
-- player does not exist/ left game
return Enum.ProductPurchaseDecision.NotProcessedYet
end
-- script below controls what happens if bought
print(player.Name.." just bought ".. receiptInfo.ProductId)
player.leaderstats.Points.Value = player.leaderstats.Points.Value + 100
return Enum.ProductPurchaseDecision.PurchaseGranted
end
MarketplaceService.ProcessReceipt = processReceipt
There’s nothing written in this script related to a sword at all. The only change after buying the product is the value of Points going up by 100. You could start with cloning a Tool into their backpack or something.
Also, if you are going to add multiple dev products, you may want to add a check for which id it is. You can grab the id of it by writing this:
local id = receiptInfo.ProductId
Also, like @Vulkarin said, you need to actually clone a sword into the player’s backpack/starter gear (only do starter gear if you want it to last more than one life). Here is an example:
local sword = game:GetService("ServerStorage"):WaitForChild("Sword")
local new = sword:Clone()
new.Parent = player.Backpack
new.Parent = player.StarterGear -- If you want it to last more than one life