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

How to check if it's a number value?

So for instance, i have this:

game:GetService("Players").randomplayer.Chatted:Connect(function(msg)
       if msg == "range" then

end
end)

How would i check if after the range, it's a number value and what number it is?

I think it's something to do with using dots like "range" .. something i don't know though..

17 comments

0

don't use :connect, its deprecated, use :Connect instead

0

ok, but like that doesn't help me here?

0

if tonumber(msg) then

0

ok then, how do i store the value i get

0

local num = tonumber(msg); if num then

0

you could use string.sub and convert to unicode/ascii and check if it's within the range 48 to 57.

0

also, tonumber() does not check if it's a number, it just converts a string to a number. So if they don't say a number it will cause an error.

0

local playerId = "1234567890" local newPlayerId = tonumber(playerId) print(newPlayerId) >>>123456789

0

how would i apply that to my script, im sort of stupid

0

Lol, you're not stupid. I'll write something up in a minute

0

thank you my good sir

0

Tbh, unicode might be unnecessary, so i'm just checking

0

Alright

0

cant u just use if tonumber(string) then

0

it'll return nil if its not a number

0

if i do that it says attempt to compare number with nil

0

if tonumber("hello") then -- false, if tonumber("1") then -- truthy

1 answer

i would use string.sub

game:GetService("Players").randomplayer.Chatted:Connect(function(msg)
       if string.sub(msg, 1, 5) == "range" then
	local num = tonumber(string.sub(msg, 6,#msg))
end
end)

also .. is used for "concatenating" string together

print("Hello " .. "World")
>Hello World

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