Convert string to number
Hello, I am a beginner in scripting and I ran into a problem. I dont really know how to use tonumber. I want to convert the Text variable, which is 999999999 to a number(if I run it without doing anything it gives the error: attempt to compare string with number). I currently have this:
>local Players=game:GetService("Players")
local player=Players.LocalPlayer or Players:GetPropertyChangedSignal("LocalPlayer"):wait()
local Text=script.Parent.Text
local a=tonumber(Text) --This is most likely wrong
while true do
script.Parent.Text=player.leaderstats.Money.Value
if a>9999999999 then
Text='>1B'
end
end
This times out when the game starts. Why and how do I fix this?
I edited the script to this but now it gives the error attempt to compare number with nil
local Players=game:GetService("Players")
local player=Players.LocalPlayer or Players:GetPropertyChangedSignal("LocalPlayer"):wait()
local Text=script.Parent.Text
while true do
if tonumber(Text)>999999999 then
Text='1B+'
else
Text=player.leaderstats.Money.Value
end
end
Posted Dec 25, 2019, 6:04 PM UTC · edited
Is this what you mean?
local value = 5 -- delete "5" and get your players money
local stringvalue = tostring(value)
print(stringvalue)