So I got two small scripts one for tools that are given if u buy the dev product or Cash given and somewhy when I join only one works and when I delete one script of those the other works perfectly but I need both and IDK if I can combine them but ye:
ServerScriptService(ServerScript)
local MPS = game:GetService("MarketplaceService")
local toolFolder = game.ServerStorage.DevProducts -- Tool storage
-- π Load Cash Dev Products (from ModuleScript in ReplicatedStorage)
local function getCashDevProducts()
local success, cashDevProducts = pcall(function()
return require(game.ReplicatedStorage:WaitForChild("DevProducts")) -- Ensure it exists
end)
if not success then
warn("β Failed to load cash dev products!")
return {} -- Return empty table to avoid breaking the script
end
print("β
Cash Dev Products Loaded:", cashDevProducts)
return cashDevProducts
end
-- π Tool Dev Products (stored inside this script)
local toolDevProducts = {
[3235590181] = { Tool = "Invisible" },
[1828475960] = { Tool = "Speed" },
[3228363764] = { Tool = "Aura" }
}
-- π Function to merge Cash & Tool Products
local function getMergedDevProducts()
local cashDevProducts = getCashDevProducts()
-- Merge tools into cash products table
for productId, toolData in pairs(toolDevProducts) do
cashDevProducts[productId] = toolData
end
print("π Final Merged DevProducts:", cashDevProducts)
return cashDevProducts
end
-- π°π Handle Purchases
MPS.ProcessReceipt = function(receiptInfo)
print("π ProcessReceipt triggered. Product ID: " .. tostring(receiptInfo.ProductId))
local player = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
if not player then
print("β Player not found!")
return Enum.ProductPurchaseDecision.NotProcessedYet
end
-- π Refresh & Merge Dev Products each time
local devproducts = getMergedDevProducts()
-- Get product data
local productData = devproducts[receiptInfo.ProductId]
if not productData then
print("β Error: No Developer Product found for Product ID: " .. tostring(receiptInfo.ProductId))
return Enum.ProductPurchaseDecision.NotProcessedYet
end
print("β
Found product data for: " .. tostring(receiptInfo.ProductId))
-- π° Handle Cash Purchases
if productData.Cash then
print("π° Adding cash: " .. productData.Cash .. " to player " .. player.Name)
local leaderstats = player:FindFirstChild("leaderstats")
if not leaderstats then
print("β Error: leaderstats not found! Creating one.")
leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
end
local cashStat = leaderstats:FindFirstChild("Cash")
if not cashStat then
print("β Error: Cash stat not found! Creating one.")
cashStat = Instance.new("IntValue")
cashStat.Name = "Cash"
cashStat.Parent = leaderstats
end
-- Update Cash
local oldCash = cashStat.Value
cashStat.Value = cashStat.Value + productData.Cash
print("β
" .. player.Name .. " cash updated: " .. oldCash .. " β‘ " .. cashStat.Value)
end
-- π Handle Tool Purchases
if productData.Tool then
print("π§ Granting tool: " .. productData.Tool)
local inventory = player:FindFirstChild("Inventory")
if not inventory then
inventory = Instance.new("Folder")
inventory.Name = "Inventory"
inventory.Parent = player
end
-- Check if player already has the tool
local existingTool = inventory:FindFirstChild(productData.Tool)
if existingTool then
print("β»οΈ Removing existing tool before granting a new one.")
existingTool:Destroy() -- Remove old tool
end
-- Grant the tool
local tool = toolFolder:FindFirstChild(productData.Tool)
if tool then
local clonedTool = tool:Clone()
clonedTool.Parent = inventory
print("β
Tool '" .. productData.Tool .. "' added to Inventory!")
else
print("β Error: Tool '" .. productData.Tool .. "' not found in ServerStorage.DevProducts!")
end
end
print("β
Purchase process completed for Product ID: " .. tostring(receiptInfo.ProductId))
return Enum.ProductPurchaseDecision.PurchaseGranted
end
ReplicatedStorage(ModuleScript)
local devproducts = {}
devproducts[1827603254] = { Cash = 50 }
devproducts[1827608966] = { Cash = 200 }
devproducts[1827625322] = { Cash = 500 }
devproducts[1827630970] = { Cash = 1000 }
devproducts[1827632701] = { Cash = 2500 }
devproducts[1827656787] = { Cash = 5000 }
devproducts[1827657912] = { Cash = 10000 }
devproducts[1827659233] = { Cash = 20000 }
devproducts[1827659880] = { Cash = 50000 }
return devproducts