Printing a random output onto a gui for the player to see

Hello. I’m pretty new to Lua and I’ve been tinkering around in studio and making small things. I am trying to make something that prints off a random number onto a gui from two points (e.g 1-100) every two seconds. I’ve been messing around for a bit and looking around and the devforum but I cannot seem to find the problem. Again, I’m pretty new to Lua so I apologize if this sounds like a stupid question. Thanks!

this is what I’ve got so far

local TextLabel = script.Parent 

TextLabel.Visible = true 
if TextLabel.Visible then

		wait (1)

		TextLabel.text = (math.random(1,255))

	end

You create while loop

while true do
wait(1)
if TextLabel.Visible then
--code
end
end)

1 Like

As @Miserable_Haven said, you should make a while loop to make a loop that changes something randomly.

code :

local TextLabel = script.Parent

TextLabel.Visible = true
if TextLabel.Visible then
    while wait(2) do -- Loop start, this will make the text become random number every 2 seconds.
        TextLabel.Text = tostring(math.random(1,255))
    end -- If you wanna stop this loop, you should use "break" function to stop
end
2 Likes

Thank you, this worked. I appreciate the help, have an awesome night/day!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.