--[[
To make another trader, duplicate a trader and change the proximity prompt text in their UpperTorso
ActionText: "FinalItemName"
ObjectText = "ItemRequired: 0/AmountRequired"
]]

local function trade(PP)
	local char = plr.Character
	if not char then return end
	local tool = char:FindFirstChildWhichIsA("Tool")
	if not tool or not tool:FindFirstChild("Handle") then return end
	local args = string.split(PP.ObjectText, ": ")
	local required, amount = args[1], args[2]
	if not required or not amount then return end
	args = string.split(amount, "/")
	local given,max = args[1], args[2]
	given = tonumber(given)
	if tool.Name == required then
		given +=1
		local final = given >= tonumber(max)
		events.TradeItem:FireServer(PP, final)
		if final then
			PP.ObjectText = "Finished!"
		else
			PP.ObjectText = required .. ": " .. tostring(given) .. "/" .. max
		end
	end
end

NPCs.Seller.UpperTorso.ProximityPrompt.Triggered:Connect(function(plr)
	local char = plr.Character
	if not char then return end
	local tool = char:FindFirstChildWhichIsA("Tool")
	if not tool or not tool:FindFirstChild("Handle") then return end
	local res = tool.Handle:FindFirstChild("Price")
	if res then
		tool:Destroy()
		plr.Wallet.Value += res.Value
	end
end)
for i,trader in NPCs.Traders:GetChildren() do
	local PP = trader.UpperTorso.ProximityPrompt
	PP.Triggered:Connect(function()
		trade(PP)
	end)
end
