Checking ClassName or using IsA

Is there a performance difference or are they the same?

2 Likes

They both do similar things, but they also have their differences. :IsA() respects inheritance, while ClassName does not. If you don’t understand it here’s an example:

If we have a frame, its ClassName property will only be read as Frame, despite it being a GuiObject and an Instance. :IsA(), however, will respect the object’s class inheritance and will return true if the parameter is equal to any of the classes the the object does inherit.

7 Likes

Performance impacts are likely miniscule. What @dukzae is a valid use along with allowing for cleaner code. IsA() returns as a bool making for cleaner code when used in logic statements.

if part.ClassName == "Part" then
    print("Hello world!")
end

vs

if part:IsA("Part") then
    print("Hello world!")
end
2 Likes

I know that IsA respects inheritance and ClassName does not, I was asking if there is a performance difference.

2 Likes

Hey ayyildizlibayrak742!

There is technically a ‘performance difference’ but it is so miniscule you would never be able to notice it. It is likely an immesurable difference.

1 Like

I ran a test and IsA was inevitably a little bit slower because it checked for more things, but the difference is so small that it will probably not affect anything.

image

1 Like

hey this is not related to your problem, but you just helped me figure out a problem I was having with a custom plugin I built. I had no idea about the inheritance respect problems. thank you so much!!!

3 Likes