Im trying to make a game that loops rounds (like Deathrun, Murder, etc).. The looping works well but i need an efficient way to detect win/lose situations.. It runs the game function to check if it returns a lose or a win.. And the timer is inside the game function and it checks if the goal part has been touched every second. If it doesnt get touched and players run out of time, the game restarts.. I couldn't come up with a way to check if the players are all dead. (I have a table of players that are in the game) This whole system seems pretty horrible to me for some reason. Anyone has a better idea for me to improve it?
This is what I got, hope it helps
function gamefinished() --better to do this outside the loop otherwise it gets done each time, but put this back to its original sate if game_time changes? gameTime=game_time-10 for i=game_time,0,-1 do if i<=game_time and i>=gameTime then msg.Value = "The door will open in " .. (i - gameTime) else msg.Value = "Time left: " .. i end wait(1) --there is no faster way to do this becouse lua lack a switch or case function :( if gameend then return "win" elseif i == 0 then return "timout" elseif #igplyrs == 0 then return "fail" end gaim = gamefinish() if gaim == "win" then msg.Value = "The players made it out alive!" wait(3) elseif gaim == "fail" then msg.Value = "The players lost!" wait(3) elseif gaim == "timout" then msg.Value = "The players ran out of time!" wait(3) end end end