Help with Zeds tycoon kit

So I was just making dev products for my tycoon and then after testing them 5 times, it only gave me the money 3 times. It’s a pretty old script aswell but I have no idea how to fix it.

function getPlayerFromId(id)
for i,v in pairs(game.Players:GetChildren()) do
if v.userId == id then
return v
end
end
return nil
end
local MarketplaceService = game:GetService(“MarketplaceService”)
MarketplaceService.ProcessReceipt = function(receiptInfo)
local productId = receiptInfo.ProductId
local playerId = receiptInfo.PlayerId
local player = getPlayerFromId(playerId)

if productId == 1228719854 then
	local cashmoney = game.ServerStorage.PlayerMoney:FindFirstChild(player.Name)
	if cashmoney then
		cashmoney.Value = cashmoney.Value + 2000
		print("2000")
	end
end
return Enum.ProductPurchaseDecision.PurchaseGranted

end

Take a look at the official API for this topic:
https://developer.roblox.com/en-us/api-reference/callback/MarketplaceService/ProcessReceipt

1 Like

I tried cleaning, handling errors, and adding some prints to your code. Perhaps it helps identify the problem(errors will show up in the console as warns):

local MarketplaceService = game:GetService("MarketplaceService")
local ServerStorage = game:GetService("ServerStorage")
local Players = game:GetService("Players")

local accept = Enum.ProductPurchaseDecision.PurchaseGranted 
local deny = Enum.ProductPurchaseDecision.NotProcessedYet

MarketplaceService.ProcessReceipt = function(receiptInfo)
	local productId = receiptInfo.ProductId
	local player = Players:GetPlayerByUserId(receiptInfo.PlayerId)
	if not player then warn("player with userId "..receiptInfo.PlayerId.." wasn't found") return deny end 
	
	if productId == 1228719854 then
		local PlayerMoney = ServerStorage:WaitForChild("PlayerMoney", 5) 
		if not PlayerMoney then warn("PlayerMoney of "..player.Name.." wasn't found") return deny end 
		local cashmoney = PlayerMoney:WaitForChild(player.Name, 5)  
		if not cashmoney then warn("cashmoney of "..player.Name.." wasn't found") return deny end 
		cashmoney.Value += 2000
		print("Product purchase succeed for "..player.Name)
		return accept 
	end
	return accept
end
1 Like

Thank you I think this will help alot!

1 Like