How do i get number even negative inside of an text?

as you read the title, here’s my problem :

            local color = Color3.new(0,255,0)
            local numMatch = string.match(v, "%d+")
            local num = tonumber(numMatch)
            print(num) -- printing the number found in the text
            if num < 0 then
                color = Color3.new(255,0,0)
                print("false")
            else
                print("true")
            end
            self.sts.Text = self.sts.Text..'<mark><font color="rgb('..color.R..','..color.G..','..color.B..')">'..v..' </font></mark>\n

this is an part of my code that changes text color declared by its own value but when this table was inserted into the code which only return positive numbers:

the table:

{"+10% MoveSpeed,
"-5% Atk",
"+100% Luck"}

the printed:

10
true
5 -- wrong
true -- which lead to this
100 
true

this is weird because if the number is negative then the printed should be false and also the number was converted into positive

sorry for poorly explaining, anyhelp is appreciated

1 Like

im not entirely sure, but you can use escape characters for symbols in strings.
instead say this:
“-\5% Atk”,

4 Likes

seems like it didnt work but ill try to explain further:
i tried to put -100 inside the table like this:

{"+10% MoveSpeed,
"-5% Atk",
"+100% Luck",
"-100",}

but the output still print 100 instead of -100

btw tysm for responding

1 Like
local color = Color3.new(0,255,0)
local numMatch = string.match(v, "-?%d+")
local num = tonumber(numMatch)
print(num)
if num < 0 then
    color = Color3.new(255,0,0)
    print("false")
else
    print("true")
end
self.sts.Text = self.sts.Text..'<mark><font color="rgb('..color.R..','..color.G..','..color.B..')">'..v..' </font></mark>\n'

See if this works, pretty sure the problem was how you string.matched() it

1 Like

the code is working

tysm for helping!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.