Can we detect what type a variable is?

i need a check if the variable is a object value. there is string value, numbervalue and boolanvalue in type()
but i need to check if variable is a object value ^^.

1 Like

You can use the type() and typeof() global functions to check what the variable is, I believe. Should work with the Value objects, though not sure.

Otherwise, if not the object itself, try using the Value property instead.

3 Likes

typeof(var) == "Instance" will tell you whether or not the variable is an instance (Roblox object). All instances have an IsA method, so once you’ve verified the variable is an instance, var:IsA("ObjectValue") will tell you if the variable is an ObjectValue:

if typeof(var) == "Instance" and var:IsA("ObjectValue") then
    -- ...
end
14 Likes

You can do this through several ways …

local val  =  Instance.new("NumberValue")
    val.Parent = workspace
       if val:IsA("NumberValue") then
	print("number value")------> true !!
end
 
   local bool = true--we basically set a boolean right here
   
    print(type(bool))--------> boolean , it works !

        if type(bool)=="boolean" then 
	
          print("The variable was a boolean")------> True !!

end
3 Likes

Also typeof is roblox specific , you could do

    local bool = true
 
     print(typeof(bool))-------> boolean

--it's nearly the same
      print(type(bool))----->boolean