local function c(c)local f=random:NextInteger(1,100)local V if f>92 then V=torch:Clone()elseif f>80 then V=gravityFuel:Clone()elseif f>10 then V=repairKit:Clone()elseif f>5 then V=smallCargo:Clone()elseif f>3 then V=largeCargo:Clone()else V=broom:Clone()end V.Position=c V.Parent=workspace.Tools V:SetNetworkOwner(nil)end return function()local f=RoomManager.getRooms()for f,V in pairs(f)do local Y=V:getRegions()local W=TOTAL_TOOLS_PER_ROOM/#Y for f,V in pairs(Y)do for f=1,W,1 do local Y=getRandomClearLocationInRegionAsync(V,AREA_CLEAR_SIZE)c(Y)end end end end

local function createRandomToolAtPosition(position)
	local randomPick = random:NextInteger(1, 100)

	local tool
	if randomPick > 92 then
		tool = torch:Clone()
	elseif randomPick > 80 then
		tool = gravityFuel:Clone()
	elseif randomPick > 10 then
		tool = repairKit:Clone()
	elseif randomPick > 5 then
		tool = smallCargo:Clone()
	elseif randomPick > 3 then
		tool = largeCargo:Clone()
	else
		tool = broom:Clone()
	end

	tool.Position = position

	tool.Parent = workspace.Tools

	tool:SetNetworkOwner(nil)
end

return function()
	local rooms = RoomManager.getRooms()

	for _, room in pairs(rooms) do
		local regions = room:getRegions()
		local toolsToSpawnPerRegion = TOTAL_TOOLS_PER_ROOM / #regions

		for _, region in pairs(regions) do
			for i = 1, toolsToSpawnPerRegion do
				local position = getRandomClearLocationInRegionAsync(region, AREA_CLEAR_SIZE)

				createRandomToolAtPosition(position)
			end
		end
	end
end
