Abstract Class validation

I’m making a plugin that takes in a class from a TextBox (classes inheriting from GuiBase), and has to validate if said class exists.

So far, I tried the simplest possible solution, a wrapping pcall around Instance.new(). This works for standard, Creatable classes:

local target = "Frame"
local type_exists = pcall(function()
    Instance.new(target)
end)
print(type_exists)
-- Output: true

However, if target were a valid, but abstract (NotCreatable) class, Instance.new() would throw an error (Unable to create an Instance of type "..."). This makes pcall return false, even though the class exists, like this:

local target = "GuiBase" -- any abstract class (except GuiMain. that works for some reason)
local type_exists = pcall(function()
    Instance.new(target) -- Unable to create an Instance of type "GuiBase"
end)
print(type_exists)
-- Output: false

Does anyone have an idea on how to do this without having to manually hardcode a list of every possible class? (Creatable and NotCreatable)

Try game.ReflectionService:GetClass(...)

image

1 Like

Yep, sounds about right. Thanks!