I made a gui shop for buy cash in game [TYCOON] I made 2 test "Buy 500 Cash" and " Buy 1000 Cash" The 1000 works the 500 not
This script going in my TextButtom from my gui; [1000 Cash]
local productId = 22197517 local player = game.Players.LocalPlayer script.Parent.MouseButton1Click:connect(function() Game:GetService("MarketplaceService"):PromptProductPurchase(player, productId) end)
This script in starterpack;
local MarketplaceService = Game:GetService("MarketplaceService") local ds = game:GetService("DataStoreService"):GetDataStore("PurchaseHistory") CASHID = 22197517 -- Put the Developer Product ID here MarketplaceService.ProcessReceipt = function(receiptInfo) local playerProductKey = "player_" .. receiptInfo.PlayerId .. "_product_" .. receiptInfo.ProductId local numberBought = ds:IncrementAsync(playerProductKey, 11) for i,v in pairs (game.Players:GetChildren()) do if v.userId == receiptInfo.PlayerId then if receiptInfo.ProductId == CASHID then lds = v:FindFirstChild("leaderstats") if lds ~= nil then cs = lds:FindFirstChild("Cash") --Change to your leaderstat if cs ~= nil then cs.Value = cs.Value + 1000 --Change to the amount you want this to add end end end end end return Enum.ProductPurchaseDecision.PurchaseGranted end
This works but when in do the 500 cash [First script the same] Starterpack
local MarketplaceService = Game:GetService("MarketplaceService") local ds = game:GetService("DataStoreService"):GetDataStore("PurchaseHistory") CASHID = 22197521 -- Put the Developer Product ID here MarketplaceService.ProcessReceipt = function(receiptInfo) local playerProductKey = "player_" .. receiptInfo.PlayerId .. "_product_" .. receiptInfo.ProductId local numberBought = ds:IncrementAsync(playerProductKey, 1) for i,v in pairs (game.Players:GetChildren()) do if v.userId == receiptInfo.PlayerId then if receiptInfo.ProductId == CASHID then lds = v:FindFirstChild("leaderstats") if lds ~= nil then cs = lds:FindFirstChild("Cash") --Change to your leaderstat if cs ~= nil then cs.Value = cs.Value + 500 --Change to the amount you want this to add end end end end end return Enum.ProductPurchaseDecision.PurchaseGranted end
This does not work... And i already did change
local numberBought = ds:IncrementAsync(playerProductKey, 1) --To 11 or 14 (14 is number where product is)
I hope some one can help me Thanks you :)
To have multiple Developer products, you have to check the ProductId of the receiptInfo. And you'd have to have separate Developer Products.
local MarketplaceService = Game:GetService("MarketplaceService") local ds = game:GetService("DataStoreService"):GetDataStore("PurchaseHistory") local thousandCash = 00000 --Put the ID for the thousand cash buy local five_hundredCash = 000000 --ID for 500 cash buy MarketplaceService.ProcessReceipt = function(receiptInfo) local playerProductKey = "player_" .. receiptInfo.PlayerId .. "_product_" .. receiptInfo.ProductId local numberBought = ds:IncrementAsync(playerProductKey, 1) for i,v in pairs (game.Players:GetChildren()) do if v.userId == receiptInfo.PlayerId then if receiptInfo.ProductId == five_hundredCash then local stat = v.leaderstats:FindFirstChild("Cash") if stat ~= nil then stat.Value = stat.Value + 500 end elseif receiptInfo.ProductId == thousandCash then local stat = v.leaderstats:FindFirstChild("Cash") if stat ~= nil then stat.Value = stat.Value + 1000 end end end end return Enum.ProductPurchaseDecision.PurchaseGranted end