Attempt to index nil with GetChildren

function getValues(truck)
	local slot
	local sortedslots = {}
	local slots = truck.LootCrate.Slots
	for i,v in pairs(slots:GetChildren()) do
		table.insert(sortedslots,tonumber(v.Name:sub(v.Name:len(), v.Name:len())))
	end
	table.sort(sortedslots)
	print(slots:FindFirstChild("Slot"..3-1):GetChildren()[1])
	for i,v in pairs(sortedslots) do
		print(i,v)
		if not slots:FindFirstChild("Slot"..v):GetChildren()[1] and slots:FindFirstChild("Slot"..v-1):GetChildren()[1] == nil  and v-1 ~= sortedslots[1] then
			print("no child")
			slot = truck.LootCrate.Slots:FindFirstChild("Slot"..v)
		else
			print("child")
		end
	end
	return slot
end

The error is on this If Statement

if not slots:FindFirstChild("Slot"..v):GetChildren()[1] and slots:FindFirstChild("Slot"..v-1):GetChildren()[1] == nil  and v-1 ~= sortedslots[1] then
			print("no child")
			slot = truck.LootCrate.Slots:FindFirstChild("Slot"..v)
		else
			print("child")
		end

either there is no child of slots named "Slot"..v or there is no child of slots named "Slot"..v-1

It’s the issue of V-1, I want the code to run if it there is no child in there, I have no idea why it’s causing an error when it would just be the third object

in that case its causing an error because slots:FindFirstChild("Slots"..v-1) is nil, and you cant :GetChildren() of nil