How do I code a Developer Product script that gives you a certain amount of cash when you purchase the Developer Product? Example: Buy a Developer product for 10 R$ > Get 1,000 Cash
COMMUNITY QUESTION
How do I code a Dev. Product script that...?
1 answer
--Put this script in ServerScriptService.
--TIP: Press F9 during game for debugging.
local MarketplaceService = Game:GetService("MarketplaceService")
local currency = "Points" --Change
--Forces save to ensure no loss of data.
function SaveStats(player)
player:SaveNumber(currency, player.leaderstats:FindFirstChild(currency).Value)
end
-- IDs (Change the numbers to match the IDs of your developer products. You may copy more.)
local productId01 = 000000
local productId02 = 000000
local productId03 = 000000
local productId04 = 000000
MarketplaceService.ProcessReceipt = function(receiptInfo)
--local playerProductKey = "player_" .. receiptInfo.PlayerId .. "_Points"
local Player = Game.Players:GetChildren()
for i = 1, #Player do
if Player[i].userId == receiptInfo.PlayerId then
prodId = tonumber(receiptInfo.ProductId)
local h = Instance.new("Hint", Player[i])
--Purchase Points. Change the numbers however you desire.
if prodId == productId01 then
Player[i].leaderstats:FindFirstChild(currency).Value = Player[i].leaderstats:FindFirstChild(currency).Value + 25
elseif prodId == productId02 then
Player[i].leaderstats:FindFirstChild(currency).Value = Player[i].leaderstats:FindFirstChild(currency).Value + 120
elseif prodId == productId03 then
Player[i].leaderstats:FindFirstChild(currency).Value = Player[i].leaderstats:FindFirstChild(currency).Value + 375
elseif prodId == productId04 then
Player[i].leaderstats:FindFirstChild(currency).Value = Player[i].leaderstats:FindFirstChild(currency).Value + 1337
else
h.Text = "Something went wrong."
Game:GetService("Debris"):AddItem(h, 4)
print("Something went wrong.")
wait(1)
end
SaveStats(Player[i])
h.Text = "Your points have been saved! Thank you for purchasing!"
Game:GetService("Debris"):AddItem(msg, 4)
end
end
return Enum.ProductPurchaseDecision.PurchaseGranted
end
This discussion is preserved as it was. New answers, comments, and votes are closed.
