Module and Nil Help

How would I detect if the Titles and Descriptions has nil in them.
Both printed titles not nil and descriptions not nil. (I must have nil in the module.)

Module:

return {
    ActiveNews = false,
    Titles = {{
        nil
    }},
    Descriptions = {{
        nil
    }}
}

LocalScript:

if NewsModule.ActiveNews == false then
    NewsUI.Main.Container.NoNews.Visible = true
    if NewsModule.Titles == nil then
        print("titles nil")
    elseif NewsModule.Titles ~= nil then
        print("titles not nil")
    end
    if NewsModule.Descriptions == nil then
        print("descriptions nil")
    elseif NewsModule.Descriptions ~= nil then
        print("descriptions not nil")
    end
end

does anyone know how i could do this?

The reason why Titles and Descriptions aren’t nil is because they aren’t.

They’re both assigned a table value that holds another table without anything in it.

(You also don’t need to put nil in them, just making the table empty is the same thing):

return {
    ActiveNews = false,
    Titles = {{}},
    Descriptions = {{}}
}

You can check if the tables inside of them have nothing in it using the next function:

-- Example usage
local function isEmpty(t)
  return next(t) == nil
end
--...
if isEmpty(NewsModule.Titles[1]) then
   --...
end

Unrelated

This can just be simplified to an else statement, if first condition doesn’t pass, then it’s not nil.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.