I am trying to make a game with survivors and a monster. I have set where it I choose a random player as a monster and everyone else as a survivor. Once it has chosen a monster, the survivors and the monster are teleported into the map. Then a timer will appear and will start counting down. When the timer reaches zero seconds, everyone on the map will be teleported back to the lobby and the game starts over again.It's on a while loop so the game never ends. The problem is if someone is the monster and they leave, how can I make the players on the map spawn back to the lobby and restart the loop so the timer will not continue while everyone is in the lobby.
Edit:
while wait() do
-- Assign roles
survivors = = game:GetService("Players"):GetPlayers()
monster = players[math.random(1, #players)]
timer = 50
-- Teleport players to map
for _, player in pairs(game:GetService("Players"):GetPlayers()) do
player.Character.HumanoidRootPart.CFrame = CFrame.new(Vector3.new(x ,y ,z))
end
-- Starts the timer
repeat
timer = timer - 1
wait(1)
until timer == -1
print("Game ended!")
--Teleport back to lobby
for _, player in pairs(game:GetService("Players"):GetPlayers()) do
player.Character.HumanoidRootPart.CFrame = CFrame.new(Vector3.new(x ,y ,z))
end
end

3 comments
It'd be nice if you'd show us the script.
put while true do at the top of the script you want to repeat and end at the bottom of the script you want to reapeat
I updated it with the code. I don't think I needed to add it but oh well