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

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

Asked by 3 years ago

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??

01local text = script.Parent
02 
03 
04text:GetPropertyChangedSignal('Text'):Connect(function()
05    if type(text.Text) == 'string' then
06        print('This text is a string')
07    elseif type(text.Text) == 'number' then
08        print('This text is a number')
09    end
10end)

2 answers

Log in to vote
0
Answered by 3 years ago

Solved

Ad
Log in to vote
0
Answered by 3 years ago

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

1local myString = "1.23"
2local myNumber = tonumber(myString)
3 
4if (type(myNumber) == "number") then
5    -- do something with myNumber
6else
7    -- myString cannot be evaluated as a number
8end

Answer this question