Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by 9 years ago

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

Log in to vote
1
Answered by 9 years ago

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.

0
Thank you :) TheDeadlyPanther 2460 — 9y
Ad

Answer this question