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

How to detect the string value if it is a number or the text ?

So i am currently making a timer for my obby game, i want to put the s after the number (like 10s) but i want the script not put the s after word (hellos <- weird) so i want the script to recognize the value is the number or it is word

--this is what i have tried (not full script )
if value.Value >= 0 then
script.Parent.Text = value.Value.."s"
else
script.Parent.Text
end

That didn't work because the output give me an error Attempt to compare number and string Help are much appreciated :D Thanks for reading

1 answer

✓ Accepted answer

You can use the tonumber() operator to test if a string is a number or not.

local label = script.Parent

if tonumber(label.Text) then -- If it's not a number, it will return nil, which is considered false
	label.Text = label.Text .. "s"
end

You don't need a second statement if you are not going to change anything when a string is detected

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