So i’m not that much of a scripter but iv’e encountered a problem. As you can see from the picture below, i am letting the intermission run down, and check if there are 2 or more ‘ready’ players to play when its done counting down. However, if there is less than 2 players, i want to skip all the way to the end (or back to the beginning) so that the intermission can countdown again and so on. Is there a possible way to do this?
My preference is to make an intermission function where the intermission runs, and a starting round function (that chooses the map, etc) that is called when the intermission is finished. Here’s what I mean.
local function StartRound()
local chosenMap = Round.SelectMap()
local clonedMap = chosenMap:Clone()
clonedMap.Name = "Map"
clonedMap.Parent = workspace
--Whatever else is here
end
local function StartIntermission()
while wait() do
local AvailablePlayers = {}
Round.Intermission(20)
for i, v in pairs(game.Players:GetPlayers()) do
if not v:FindFirstChild("InMenu") then
table.insert(AvailablePlayers, v)
end
end
if #AvailablePlayers < 2 then
status.Value= "Two Players Required (0/2)"
wait(1)
StartIntermission()
return
end
StartRound()
end
end
Basically I separated the intermission function and the starting round function. Within the intermission function, I checked to see if there are enough players, and if there aren’t, I used recursion to start the intermission again without proceeding to the rest of the code. If there are enough players the round will start with StartRound()
Thank you, and yes this is from Alvin’s tutorials. I was going to make a piggy based game before he posted his videos, but as hes posted tutorials on how to make the whole game, might as well save weeks of intense thinking and scripting.
I appreciate the time and effort that went into this reply. However, i think ill be using @Nerkonl 's method as it is a much simpler way of doing it. I might change my mind and use your method if i feel uncomfortable.
Iv’e decided to leave the StartRound because there is actually a lot more code under the StartIntermission than what i showed you in the first picture. If i put the StartIntermission outside the function it would just loop. Is there anyway to make it only run once?.
Nevermind, i added the while loop in the function and thought that when the StartIntermission() function was called, it actually went back to where the function is instead of performing the function on the line is was called. Hope you understand