Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do you check if a variable is a number or a string?

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

2 comments

0

Just wanted to say, I honestly love the C++ syntax you've got going on. It's always been aesthetically pleasing me lmao.

0

It's habits from Java, I know him from the SH discord server :p

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:

Roblox Wiki Type

##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.