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
ayoub50
(Ayoub)
August 1, 2022, 8:58pm
2
is this a localscript or a serverscript?
I tried both local and server script but they both don’t work
dotinfo
(dotinfo)
August 1, 2022, 8:59pm
4
TextLabels uses strings, use tostring()
As OP said he tried it with that, plus using tostring for stuff like that has no purpose
ayoub50
(Ayoub)
August 1, 2022, 9:04pm
7
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
Citrozi
(Citro)
August 1, 2022, 9:07pm
10
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
ayoub50
(Ayoub)
August 1, 2022, 9:09pm
13
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.
ayoub50
(Ayoub)
August 1, 2022, 9:11pm
16
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.
ayoub50
(Ayoub)
August 1, 2022, 9:48pm
18
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