Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
-1

How to have number value converted to text?

Asked by
Nidoxs 190
10 years ago

I really need help, I'm getting REALLY stressed out. Anyway PLEASE help me! :) What's wrong with this?

local CV = script.Parent.C 
local C = script.Parent.C.Value

for i = 1, 2500 do
    wait(0.01)
    if CV.Value < 2500 then
        CV.Value = CV.Value + 1
    end
end

script.Parent.Text = C

0
What's the output Bman8765 270 — 10y

1 answer

Log in to vote
2
Answered by
Perci1 4988 Trusted Moderation Voter Community Moderator
10 years ago

To convert a number to a string, you use the tostring(number) function. What this will do is attempt to convert the given number to a string, and then return that string. If no number is given, it returns nil.

tostring(50)

I'm not entirely sure what you're attempting to do. You have an if statement that affects the value of a NumberValue, but you're doing nothing to display the changing number to users.

On line 11, you set the text to whatever is was equal to at line 01, disregarding that C is no longer equal to script.Parent.C.Value(due to the for loop). If that's what you intend, it begs the question, why the loop?

We can make your loop more efficient, however, for you already have a variable (i) that is changing, so you can use that to directly set the value.

for i = 1, 2500 do
    wait() --The minimum wait time is about a 30th of a second, so you can't make it wait only 1 hundredth of a second. 
    CV.Value = i
end
0
I have a number value that increases by 1 every couple of seconds, but I want to value of the Number Value to be converted to text on a Surface Gui So say the value of the Number Value is 20 the surface gui text is = 20 then when it adds 1 the text is 21 then 22 all the way to 2500. Nidoxs 190 — 10y
0
Then you would obviously just change the text inside the loop, so it will update each time the loop iterates. I told you how to convert it to a string at the top of my post. Perci1 4988 — 10y
Ad

Answer this question