I'm making a game where when the round ends, it resets back to the intermission and then another round begins. I have to make the game repeat, but I can't put everything in a loop because there's some issues with other loops and functions. Is it possible to do this:
1 | [ Intermission code ] |
2 | [ Map voting code ] |
3 | [ Winner code ] |
4 | --Go back to line 1 |
If someone could help, that would be greatly appreciated!
There is a way called loops. Loops are basically a line of code that repeats the same thing over and over again for a certain amount of time.
For loops for example repeat code for how many times you put it, like this:
1 | for i = 1 , 10 , 0 do |
2 | --Code here |
3 | end ) |
You can watch PeasFactory's videos of loops, that's how I learned it.
1 | https://www.youtube.com/watch?v = O 2 Ikk 1 JSInw |
Theres also while true do loops which repeats code forever:
1 | while true do |
2 | --code here |
3 | end |
I think you are looking for a function? If so try something like this:
1 | local function newRound() |
2 | --Code to repeat goes here |
3 | end |
then you call the function whenever it is needed by typing
1 | newRound() |
so you get
1 | local function newRound() |
2 | --Code to repeat goes here |
3 | end |
4 |
5 | newRound() -- Runs it at the start |
You may also want to check https://developer.roblox.com/en-us/articles/Function for more on functions, and https://developer.roblox.com/en-us/articles/Remote-Functions-and-Events on how to activate it when needed!
Sorry if I was a bit vague on it, and that I couldn't give a sample code for Remote Functions and Events, but i'm still learning how to use them!
Hope this helped!