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

Unable to compare number, help?

Asked by 8 years ago

Alright, so now it's not a scripting error I'm receiving, rather the script breaking upon use. I don't see what's wrong, right clicking on script isn't giving me an option to go to Script Error, so the writer isn't seeing the issue.

function math()
    number1 = script.Parent.Name
    number6M = 24
    number6A = 20
    number7A = 25
    if number7A == number1 or number1 > number7A then  --This is line 21
        math2()
    elseif number6A == number1 or number6A < number1 then  --Line 23
        print"Ahh"
    end
end

Error from Output, "Workspace.0.Script:21: attempt to compare number with string Stack Begin Script 'Workspace.0.Script', Line 21 - global math Stack End" More than likely it will occur on Line 23 aswell.

1 answer

Log in to vote
1
Answered by 8 years ago

'number1' is a string not a number, so when you try to compare it with a number it'll error. 'number1' is really a string, you can convert a string to a number using 'tonumber()'

number1 = tonumber(script.Parent.Name)

if tonumber() can't turn the string into a number it will return nil.

function math()
    number1 = tonumber(script.Parent.Name) --we convert the name into a number
    number6M = 24
    number6A = 20
    number7A = 25
    if number7A == number1 or number1 > number7A then  --This is line 21
        math2()
    elseif number6A == number1 or number6A < number1 then  --Line 23
        print"Ahh"
    end
end
Ad

Answer this question