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.
--this is an example local XP = script.Parent -- is a textlabel that displays how much XP they have local LVL = script.Parent.Parent.TextLabel2 -- TextLabel that displays the level 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.]] LVL.text = 2 --then it would show a pop up that says you leveled up wait(3) --you leveled up pop up disappears. 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).local success, message = pcall(function() if tonumber(XP.Text) >= 2000 then -- code end end)