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

What is the best way to find out if a value is a number/string?

So, I am trying to design a script that gets the numbers in a name (E.G the name is Number56, and I'm trying to get the 56). But the names on what I'm analyzing differ, so I need to make a script that checks for numbers before it adds them. Now, I'm talking about these values

local num = 5

instead of these values (I could get the ClassName for these ones)

local num = script.NumberValue

Is there a way to check if it is a number/string like this?:

if num:IsA("Number") then
	-- code
end

ROBLOX Wiki has come up with no answers for this. Thank you :)

1 answer

✓ Accepted answer

tonumber(stringHere) will return the number representation of stringHere or nil if it cannot be converted to a number.

You might also be interested in string.find/string.match see Roblox's wiki documentation for the string class

For instance, print(tonumber(string.match("hithere54", "[%D]*([%d]*)"))) prints out 54. To learn more about how to create the matching expressions, look here.

1 comment

0

Thank you :)

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