More Help with functions

I really need Help with a function but I don’t know how to do it, I have tried but cant seem to figure it out.
Its for a soccer game I made, a function that counts the scores from two TextLables and prints which textlable has the higher Number,
Help Would Be Nice! :wink:

you can convert both to numbers by doing tonumber(someTextLabel.Text), then get the larger of the two by doing math.max(someNumber, someOtherNumber)
this would print the number that’s higher, but not tell you which one is higher

to find which one is higher, you’d do something like below whenever checking which is higher

if firstNumber > secondNumber then
   display that first text label is higher
elseif firstNumber < secondNumber then
   display that second text label is higher
else
   display tie
end

Oh, yeah! Thank you for your help

Although, I’m a bit stuck on how to use firstNumber and secondNumber
I tried but i keeps saying “White Wins” But blue actually won, I dont think i did it right

Considering it’s TextLabel’s you’re using, the .Text property of them will be returning a string, not a number, so you won’t be able to perform mathematical arithmetic on them. To append onto @4SHN’s solution, you’ll need to use tonumber() on the text label .Text value. Here’s an example:

if tonumber(TEXTVALUE1.Text) > tonumber(TEXTVALUE2.Text) then
    -- display that first text label is higher
elseif tonumber(TEXTVALUE1.Text) < tonumber(TEXTVALUE2.Text) then
    -- display that second text label is higher
else
    -- display tie
end

Something like this is what you’ll be after. :slight_smile:

EDIT: TEXTVALUE1 and TEXTVALUE2 in this case will be your TextLabel objects.

1 Like

Ok, Now i got it! Thank you all for your help!

1 Like