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