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

In a TextLabel how do i check if its a string or number??

This is what I have so far but it always says its a string and I dont know how to check if its a string or number anyone know how to fix this??

local text = script.Parent


text:GetPropertyChangedSignal('Text'):Connect(function()
	if type(text.Text) == 'string' then
		print('This text is a string')
	elseif type(text.Text) == 'number' then
		print('This text is a number')
	end
end)

2 answers

For those who might be wondering, here's how to check if a string can be evaluated as a number:

local myString = "1.23"
local myNumber = tonumber(myString)

if (type(myNumber) == "number") then
	-- do something with myNumber
else
	-- myString cannot be evaluated as a number
end

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