I'm trying to make a script that detects if a Region is empty, though nothing happens when I use an if statment to check if there is nothing in the region. Here is what I got;
local region = Region3.new(Vector3.new(1,1,1),Vector3.new(10,10,10))
local event = game.ReplicatedStorage:WaitForChild("test")
event.OnServerEvent:Connect(function(player)
local regionParts = workspace:FindPartsInRegion3(region,nil,100)
for i, parts in pairs(regionParts) do
if parts == nil then
print("yes")
else
print("erg")
end
end
end)
I don't know what I'm doing wrong, any help would be much appreciated!

3 comments
That's not all of the code. Where's the part where you define the region?
Right, sorry. I forgot to put them here.
You're attempting to run a for loop on an array if zero elements. If there is nothing in the region, the loop won't run even once and the if check becomes superfluous. Since the function returns an array, you can simply use the length operator (#) to the the number of parts found. Try it. Delete the for loop and just do print(#regionParts)