Optimizing Mass Part Selling

This can easily be fixed by yielding every x iterations, for example:

local x = 50 --yield every 50 iterations
local counter = 0
for _, container in containers do
	for i, tool in container:GetChildren() do
		if tool:HasTag("Sellable") then
			totalPrice += priceOf(tool)
			tool:Destroy()
		end
		counter += 1
		--if counter is a multiple of x(50) wait for a single frame
		if counter % x == 0 then task.wait() end
	end
end 

This basically tells the engine to run 50 iterations, wait, run 50, wait, until it ends. It makes the function not run instantly, but it reduces lag by a lot. If you want to decrease lag you make x smaller and if you want to make it faster you increase it(you must find the sweet spot).