Best way to tell if userdata is Vector3 or Model Instance?

What’s the best way to tell if userdata is Vector3 or a Model Instance?

function example(ModelOrPos)
    if isModel(ModelOrPos) then
        ModelOrPos = ModelOrPos.PrimaryPart.Position
    end
    -- Do stuff with the Vector3
end

It seems to error if you do something like

function example(ModelOrPos)
    if ModelOrPos.PrimaryPart then
        ModelOrPos = ModelOrPos.PrimaryPart.Position
    end
    -- Do stuff with the Vector3
end

Is there a good way to do this without having to resort to pcalls?

New typeof() global function - Updates / Announcements - Roblox Developer Forum

You can use typeof() but the only annoyance is it classifies a Model as an Instance. Which isn’t inaccurate but this global function can identify what something is. Be it a number, instance, string, etc.

1 Like