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

How do I check if something is a number?

How do I check if something is a number?...

3 comments

2

Use the type() function. It will compare the argument to a string value to provide a result. if type(Value) == 'number' then return true end --[[OR you can do]] if tonumber(Value) ~= nil then return true end

0

if type(variable) == 'number' end 'number' is a string value?

1 answer

✓ Accepted answer

You can use the type function to return the value of something.

local function checknumber(num)
	if type(num) == "number" then
		return true
	else
		return false
	end
end

print(checknumber(3)) --prints true
print(checknumber("hello!")) --prints false

4 comments

0

[string "stdin"]:2: attempt to index local 'num' (a number value)

0

Your code errors because you are attempting to use a method on a number type.

0

Sorry, I haven't used it in awhile. I forgot it wasn't a method. Edited.

1

No problem, thank you for your answer!

This discussion is preserved as it was. New answers, comments, and votes are closed.