Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How to get a random number and then after a certain time it changes?

Asked by 4 years ago

I think this is some of the basics, the math.random, well I wanted to ask how to make it so it changes like after 10 seconds to another number and like that in a loop?

The code i dont even know if i need to put it but here:

local randomRole = math.random(1, 3)

1 answer

Log in to vote
1
Answered by 4 years ago

Hey! You got the random number correct, and to answer this question you can just make a simply for loop, take time to read this as I will be going through how to do this.

for i = 1, 100 do -- you can obviously change this number to like 1, 500 or like 5, 6 0, or 50, 100 etc, it's not just needed at 1, 100. (this for loop is not needed
print(math.random(i))
wait(time) -- you can put anything you want here, but it has to be a numeral value, and or localized with a numeral value. aka local time = 1
end
0
Hope this helped! Nicholas1088 169 — 4y
0
why don't you just use a while wait loop?? Cynical_Innovation 595 — 4y
0
You can use that yes, but a for loop is kinda nice in this case! Nicholas1088 169 — 4y
0
It might not be, because it only runs a set number of times. SO if I were to stay in the game a hecka long time, the thing may no longer run. Please use while wait instead of for loops for these kind of problems. Cynical_Innovation 595 — 4y
Ad

Answer this question