print(#table) outputs 0 even though It’s not empty. Here’s the code:
ModuleScript:
function module:Cast(cframe:CFrame, size:Vector3, overlapParams:OverlapParams)
local humanoids = {}
local parts = game.Workspace:GetPartBoundsInBox(cframe, size, overlapParams)
for _, part in pairs(parts) do
if part.Parent:FindFirstChild("Humanoid") and not humanoids[part.Parent] then
humanoids[part.Parent] = part.Parent
end
end
return humanoids
end
LocalScript:
local humanoids = _Hitbox:Cast(cframe, size, overlapParams)
if #humanoids > 0 then
print("Not Empty: "..#humanoids)
else
print("Empty")
end
for _, humanoid in pairs(humanoids) do -- i know that the table's not empty because this prints out names
print(humanoid.Name)
end
local function FindLength(Dict)
local count = 0
for _,_ in Dict do
count += 1
end
return count
end
The underscores are used in place of the key and value (during the loop) since we are not using them. This function just loops through the dictionary and adds to the count every time it finds an element. Very simple.
Sorry for the wait, I had to go away from the keyboard. Sooo…
I came up with a different solution which takes from yours. print(#table) outputs 0 even though It’s not empty. Here’s the code:
ModuleScript:
function module:Cast(cframe:CFrame, size:Vector3, overlapParams:OverlapParams)
local humanoids = {}
humanoids.Amount = 0 -- New variable for counting
local parts = game.Workspace:GetPartBoundsInBox(cframe, size, overlapParams)
for _, part in pairs(parts) do
if part.Parent:FindFirstChild("Humanoid") and not humanoids[part.Parent] then
humanoids[part.Parent] = part.Parent
humanoids.Amount += 1
end
end
return humanoids
end
LocalScript:
local humanoids = _Hitbox:Cast(cframe, size, overlapParams)
if humanoids.Amount > 0 then
print("Not Empty: "..humanoids.Amount)
else
print("Empty")
end