You can use the IsA method, but treat it as a function:
if game.IsA( object, "Instance") then
There's a caveat, and that is that this will make an error if object isn't an instance. So you can use pcall:
local noError, wasInstance = pcall( function() return game.IsA(object, "Instance") end )
if noError and wasInstance then
You can preempt many of these pcalls by checking the type of the object is "userdata" (but this is not sufficient because Vector3, CFrame, etc are userdata, and also Lua scripts can make new userdata via newproxy):
if type(object) == "userdata" then
local noError, wasInstance = pcall( function() return game.IsA(object, "Instance") end )
if noError and wasInstance then
end
end
2 comments
This is really stupid but can't you just check if it has .Name?
Other objects can have a name:
local notAObject = {Name = "Hi"}. In a less strange example, BrickColors also have names.