Typeof() or v:IsA()

So let’s say you want to check a value in a table, is it better to use typeof() or IsA(). Here is an example:

local tab = {Health = 1000, Name = "Dead End", Emperor = true, Weapons = {Spear}}

for _,v in ipairs(tab) do
  if v:IsA("boolean") or v:IsA("table") or v:IsA("string") do
--v:IsA() or..
    print(v)
    end
     if typeof(v) == "boolean" or typeof(v) == "table" or typeof(v) == "string" do
--or typeof()
       print(v)
   end
end

Any help would be greatly appreciated!

IsA only works for Instances, so you’re going to want to use typeof() for this.

1 Like

IsA checks an Instance’s class (and considers inherited classes).
typeof checks a variable’s data type.

Your code is essentially doing:

1000:IsA("number")

which would result in an error.

1 Like