So I have this script which controls when a player makes a purchase in my game. In Roblox Studio it seems to work, but in the actual game someone purchased one of them and did not get their cash. Here is my code below if anyone is able to tell me where I went wrong or if I should use a different system:
local devproductid = 508680391
local devproductid2 = 508680924
local devproductid3 = 508681392
local devproductid4 = 508682217
local devproductid5 = 508682958
local devproductid6 = 508684424
game.ReplicatedStorage.MakePurchase.OnServerEvent:Connect(function(player, price)
player.leaderstats.Cash.Value = player.leaderstats.Cash.Value - price
end)
game.ReplicatedStorage.SkinChange.OnServerEvent:Connect(function(player, skinname)
player.CurrentWeapons.CurrentSkin.Value = skinname
end)
game.ReplicatedStorage.SkinWon.OnServerEvent:Connect(function(player, skinname)
local skinfind = player.skinfolder:FindFirstChild(skinname)
if not skinfind then
local newskin = Instance.new("BoolValue", player.skinfolder)
newskin.Name = skinname
end
end)
MarketplaceService.ProcessReceipt = function(receiptInfo)
for i, player in ipairs(game.Players:GetChildren()) do
if player.UserId == receiptInfo.PlayerId then
if receiptInfo.ProductId == devproductid then
player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + 500
end
if receiptInfo.ProductId == devproductid2 then
player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + 1100
end
if receiptInfo.ProductId == devproductid3 then
player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + 2500
end
if receiptInfo.ProductId == devproductid4 then
player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + 6500
end
if receiptInfo.ProductId == devproductid5 then
player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + 15000
end
if receiptInfo.ProductId == devproductid6 then
player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + 40000
end
end
return Enum.ProductPurchaseDecision.PurchaseGranted
end
end