How do you create a loop after the loop is broken by break

So I’m using code from my other thread: Intermission Restarting For Some Reason The problem is, that I want the loop to break but when a new round starts to make it loop again. (The reason my code looks like that is because before my code used to loop at the wrong line, but this code fixes that problem)

while true do
     wait()
     game.ReplicatedStorage.ShowVotes:FireAllClients()
     workspace.Sound1:Play()
	for i = 10,1,-1 do
		text.Value = "Intermission "..i
		wait(1)
	end
    game.ReplicatedStorage.ByeVotes:FireAllClients()
	print("Picking gamemode")
    wait()
    break
end
1 Like

This is a sever script in serverscriptservice

its less an issue of code, and more an issue of logic.
You just need to call a function when the round ends, not an infinite loop.
While loops are useful for information that you’d want constantly updating, but in this senario, it’d be better to simply set up a series of functions that can wait an indefinite amount of time until called into action.

Something like this?

        ''''
              
local function Intermission()
while true do
 wait()
 game.ReplicatedStorage.ShowVotes:FireAllClients()
 workspace.Sound1:Play()
for i = 10,1,-1 do
	text.Value = "Intermission "..i
	wait(1)
end
game.ReplicatedStorage.ByeVotes:FireAllClients()
print("Picking gamemode")
wait()
break
end
end
Intermission()

              '''
  // Game round script has ended and called Intermission()        
local function Intermission()
   game.ReplicatedStorage.ShowVotes:FireAllClients()
   workspace.Sound1:Play()

  for i = 10,1,-1 do
	text.Value = "Intermission "..i
	wait(1)
  end // Call next module, in this case your ByeVotes area
end

local function LaunchNextRound()
    game.ReplicatedStorage.ByeVotes:FireAllClients()
    print("Picking gamemode")
   *instert game mode selection code here* 
end

 local function Gamemode1()
*insert game mode code here*
  Call  Intermission()

this is heavy on the psudo code, but its an example of the logical structure I would suggest.

1 Like

How would you call the LanchNextRound function if the script doesn’t know what it is yet? (Sorry I’m a beginning scripter, and I don’t know much yet

as I pointed out, Im showing you the logical structure, not the actual code.

I’d suggest looking into functions within lua
https://www.lua.org/pil/5.html

Kinda like this?

       ''''
               
 local function Intermission()
 wait()
 game.ReplicatedStorage.ShowVotes:FireAllClients()
 workspace.Sound1:Play()
for i = 10,1,-1 do
	text.Value = "Intermission "..i
	wait(1)
end
end
Intermission()

local function Choose()
game.ReplicatedStorage.ByeVotes:FireAllClients()
print("Picking gamemode")
end
Choose()
            '''

But I still don’t understand how you can call a function even if the script doesn’t know what the function is

Never mind, the problem still doesn’t change. It goes through, and stops when the round is over

You’ll have to set up the code so the preceding function calls the next; Ie
intermission()
calls Choose()
and then Choose() calls your game mode
and then Gamemode() calls your EndGame/Intermission.

This structure will create your logical loop.

1 Like

put it in a function like so

function MyFunction()
    while true do
         wait()
         game.ReplicatedStorage.ShowVotes:FireAllClients()
         workspace.Sound1:Play()
	     for i = 10,1,-1 do
		    text.Value = "Intermission "..i
		    wait(1)
	    end
        game.ReplicatedStorage.ByeVotes:FireAllClients()
	    print("Picking gamemode")
        wait()
        break
    end
end

Then call function every time u want loop to run :sunglasses:

Ok In tried that, and called the function after a round is over. It still doesn’t loop back to the beginning

Hey um @yenyang4 and @Instance0new, would something like this work?

           ''''

    local function Pick()
    game.ReplicatedStorage.ByeVotes:FireAllClients()
    print("Picking gamemode")
    wait()
    Gamemode()
end


function Intermission()
     wait()
     game.ReplicatedStorage.ShowVotes:FireAllClients()
     workspace.Sound1:Play()
     for i = 10,1,-1 do
	    text.Value = "Intermission "..i
	    wait(1)
    end
 Pick()
end

                 '''
1 Like

Ok now in in the same script, it won’t print “yay”

   ''''
     function Intermission()
     wait()
     game.ReplicatedStorage.ShowVotes:FireAllClients()
     workspace.Sound1:Play()
     for i = 10,1,-1 do
	    text.Value = "Intermission "..i
	    wait(1)
    end
 print("Yay")
 game.ReplicatedStorage.Function:Fire()
 print("yay2")
end


   '''

Could anyone please tell me why?