Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Level up system using >= for text?

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!

2 comments

1

I need to know too

0

Usually when i use xp or levels i place the number inside a numbervalue to make life easier

1 answer

✓ Accepted answer

###You can do this with the 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)

1 comment

1

Thanks, been trying to figure this out for a while now, so I'll definetly accept it.

This discussion is preserved as it was. New answers, comments, and votes are closed.