How to make a random number between "1" and "1000" appear on a text box every few seconds?

Hey guys,

So I don’t normally script things but recently I’ve been trying to learn some new things to help me later on down the road. I recently was making a machine with some gizmos and gadgets on it and I figured I’d add a text box with random numbers appearing every One second. I know how to do the bare minimum and print the numbers to the output tab, but I don’t know how to apply it to a a text box.

As I’m sure a lot of you can tell, this is the script that randomly prints numbers to the output tab every second out of a possible 1 in 1000 numbers

While true do
    wait (1)
    print(math.random(1,1000))
end

Something like this is essentially what I’m trying to accomplish

Given a TextLabel gui,

local textLabel = game:GetService("StarterGui").ScreenGui.Frame.TextLabel

while wait(1) do
    local textYouWant = math.random(1, 1000)
    textLabel.Text = tostring(textYouWant)
end
2 Likes

This is right but just put the “textYouWant” variable in the while loop so there is a different number each time it loops through the while loop, instead of one random number picked when the script is executed.

1 Like

I assume I put this in a script inside a text label?

Yes, and make local textLabel = script.Parent

1 Like

Oh, you are completely right. My bad.

Just edited the script, should be fine now.

stole my word xDDDD

but if you really want to make it like what you want with the gif, try to make a delay and make the text transparency or color, depends on how you want to do it, using the object’s name and TextTransparency.

i don’t know if i explained well :frowning:

1 Like

I know this is a stupid question but, I’m not sure how exactly to set this up in the actual brick. I put a brick down, then a SurfaceGui, inside it I put a TextLabel. Where do I put the script to make numbers appear because, (and again stupid question), I cant write every number 1-1000 in the text label.

Sorry

No need to apologise, it’s fine. I’d the script inside the text label.

2 Likes

Ok so the script is inside the text label, what do I write in in the actual label for it to visibly start randomizing the numbers?

This is what you should write in the script, but instead local textLabel will be = script.Parent

1 Like

You don’t need to write anything in the text label, in the script you just write this:

But intead of:
local textLabel = game:GetService("StarterGui").ScreenGui.Frame.TextLabel

do:

local textLabel = script.Parent

1 Like

Thank you so much, And lastly, what does the textYouWant do? Do I leave it like that or put something in it?

that’s the variable that’s going to hold the random values, don’t delete it or else you would end up with an error that won’t know what the variable is when it’s attempted to be used.

1 Like

Yeeeeuuuup just figured that out lol, but It works now! Thank you all so much!

No problem! Also don’t forget to mark the topic as solved.

If you need anything else I’ll be glad to help.

1 Like

Thank you! Any other questions I have relate to more complex builds so I won’t take up your time with more of them, haha

I went back and played around with it, and I realized that as long as there’s literally anything in that space, it’ll work. Knowing that, I changed “textYouWant” to “spaghetti”! :joy:

It’s won’t work as your only changing StarterGui (the template of the UI), maybe try:

local Client = game:GetService("Players").LocalPlayer

while wait(1) do
local numberText = math.random(1, 1000)
local changeText = Client.PlayerGui.ScreenGui.Frame.yourtextnamehere
changeText.Text = tostring(numberText)
wait(0.5)
print("Okay! This got debugged! (1)")
 end
end)