TextLabel not changing text every second

I am creating a text label to create a random number text each second, but it is not working with no errors as well.

local textToUpdate = script.Parent

while wait(1) do
 textToUpdate.Text = math.random(1,10)
end

I also tried putting the function tostring() but that is also not working

is this a localscript or a serverscript?

I tried both local and server script but they both don’t work

TextLabels uses strings, use tostring()

I tried that already

char limit

As OP said he tried it with that, plus using tostring for stuff like that has no purpose

i tried it myself and its working fine for me, make sure thats a local script.

it’s possible that math.random() is picking the same number multiple times in a row, hence it appearing not to change.

1 Like

I don’t think that would be the case though, it is too unlikely to be true

1 Like

Can you show the text label in the explorer? It could be that you are referencing a different object

1 Like

try adding a print to check that it’s changing

local textToUpdate = script.Parent

while true do
  local randomnumber = math.random(1,10)
  print("New random number = "..tostring(randomnumber))
  textToUpdate.Text = tostring(randomnumber)
  task.wait(1)
end

Try this:

local textToUpdate = script.Parent

while wait(1) do
    local textNum = math.random(1,10)
    textToUpdate.Text = textNum
end

Edit: @IncredibleTeamAidan beat me to it

1 Like

the code is working fine for me,idk whats your problem can you show your explorer?

Thanks! Your code worked! I think it is oddly because I didn’t use task.wait() lol

1 Like

yeah, possibly. I don’t think wait() is going to be supported much longer, too inaccurate.

no, i think you had a bug.
[Char Limit]

I don’t think so, this morning while recording a video I demonstrated changing the color of a part to a random rgb value, I achieved this like this:

local r = math.random(0,255)
local g = math.random(0,255)
local b = math.random(0,255)

Part.Color = Color3.new(r,g,b)

That worked, however, when I tried to set the parts transparency directly to a math.random (using no variable) it didn’t work:

Part.Transparency = math.random(0,1)

(Didn’t work) this leads me to conclude it’s a bug with directly setting a value to math.random without the use of a variable.

well, i tried to use math.random directly with no variable and it worked fine for me.

1 Like

Yeah, it doesn’t happen all the time, however, when it happens that it doesn’t work, using a variable has proven to work (at least most of the time)

1 Like