So, I'm trying to make a level up system for a game I'm making but I get an error when I try to compare a string to a number. I can't figure out how I would do it since it it can only be text.
01 | --this is an example |
02 | local XP = script.Parent -- is a textlabel that displays how much XP they have |
03 | local LVL = script.Parent.Parent.TextLabel 2 -- TextLabel that displays the level |
04 |
05 | if XP.text > = 2000 then --[[ This is what I need help with, I can't quite figure out how I would compare it to string.]] |
06 | LVL.text = 2 |
07 | --then it would show a pop up that says you leveled up |
08 | wait( 3 ) |
09 | --you leveled up pop up disappears. |
10 | end |
I hope you can help ! if you can, THANKS!
tonumber
function. It attempts to convert its argument to a number, will throw error if it cannot (e.g. you passed letter arguments or userdata arguments). Because of that, you may want to wrap tonumber
in a pcall
(protected call).1 | local success, message = pcall ( function () |
2 | if tonumber (XP.Text) > = 2000 then |
3 | -- code |
4 | end |
5 | end ) |