How To Verify That Something Is A Number

I’m accepting a value from the client that is expected to be a number, and I would like to verify that it is in fact a number from the server to avoid attacks that rely on causing an error. Currently, I’m using type(parameter) to determine what it is, but I don’t know what to compare it to. Is there an enum I can use? i.e. if type(parameter) == Enum.Type.Number then

1 Like
if tonumber(1) ~= nil then
      --do stuff
end

that is how you can do it with tonumber

Oh, I thought that would error if it received an invalid argument. Is there any case in which that would error?

Use tonumber. I actual answered a similar question, over in this post

Dev post about checking Textboxs on numbers

1 Like

no, there is no error that this would cause

type and typeof return strings

print(typeof(CFrame)) --> CFrame
print(type("a")) --> string

Gotcha. I see now that using type and typeof on itself returns string. Always assumed it was an enum

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.