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

How to have number value converted to text?

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

1 comment

0

What's the output

1 answer

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

2 comments

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.

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.

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