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

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

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:

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

Answer this question