How do you check if a variable is a number or a string?
✓ ANSWER ACCEPTED
How do you check if a variable is a number or a string?
2 answers
✓ Accepted answer
local variable = --Insert Val
if (type(variable) == "string") then
--String
elseif (type(variable) == "number") then
--Number
else
--Some other
end
Hey SimplyJeremy,
You can do this simply by using type(). Like this:
local num = 1
local str = "Whatever"
if type(num) == 'number' then
print("It is a number.")
else
print("It is not a number.")
print(type(num)) -- Prints number
print(type(str)) -- Prints string
##Reference:
##I hope I helped and have a wonderful day/night.
Thanks,
Best regards,
KingLoneCat
2 comments
0
Error Line 06, finds : Error Line 08, expecting end.
0
Sorry, too used to Python xD
This discussion is preserved as it was. New answers, comments, and votes are closed.

2 comments
Just wanted to say, I honestly love the C++ syntax you've got going on. It's always been aesthetically pleasing me lmao.
It's habits from Java, I know him from the SH discord server :p