How do I Find What Kind of Value a Variable is?

How do I find what kind of value something is? I’m trying to find if a value is a stringvalue, objectvalue, numbervalue, etc. etc.

I thought maybe you could find if it’s a stringvalue by using:

if tostring(value) then...

and maybe numbervalue by:

if tonumber(value) then...

and objectvalue:

if value.Name then...

Some of these might cause an error, so wrapping it in a pcall might be necessary. Also, if a stringvalue in the second example was a ‘0’, then it would pass fine.

Is there some universal way of finding what value something is, kind of like object:IsA() but for values?

Edit: Both of the posts below are the solution, but sadly I can only mark one. Thanks guys!

You can check what a value is by using “type”. For example

print(type(value))
print(type("Hi"))
print(type(1))

if type(value) == "string" then
--Your code idk
end
1 Like

You may have better interest in typeof() as it is more verbose regarding certain types in Roblox specifically, e.g. passing in an instance into type will return userdata whereas passing it into typeof will return Instance. This is the same for other objects e.g. Vector3, CFrame, etc.

2 Likes