I know this isn't needed in any situation really, but i just wanted to know because i made a script and when i try to compare leaderstas points (int), it will say "
18:39:38.491 - LocalScript:10: attempt to compare string with userdata
" (and yes i removed some of the error message to clear unneeded text)
anyways like i said, i already know that you can just set an int value into the UI and do more magic, but i wondered if there is any way to actually convert it.
If you wanted to convert a string to a number you would use tonumber(). tonumber() takes in a string and converts it into a number, simple. You need to check if the string has only numbers or not.
Once you have the converted number, you can do anything like it just like a real number.
Here's an example:
local myString = "12344" local myConvertedNumber = tonumber(myString) print(myConvertedNumber) -- > 12344
You can even turn numbers back to strings using tostring()
local IdontLikethisNumber = 64332 local ILikethisString = tostring(IdontLikeThisNumber) print(ILikeThisString) -- > "64332"
Hope this helped you
Something that I'd like to add as an answer is to not compare the object itself but rather the property value of the object.
-- let's assume this is your points object local points = Instance.new('IntValue') -- Example of what not to do: if (points > 10) then end -- What to do instead if (points.Value > 10) then end