Im making a game and I want it so that when all the players have been killed the map destroys and the game restarts (not shutting down and rebooting. The game going on inside the game... If you get what I mean) and players get spawned back in. I already have the Spawn Points in the Lobby so i cant use Spawners. Would be great of you could help me out!
COMMUNITY QUESTION
How do I Identify if all players have been killed so the map can get destroyed?
1 answer
Make a table called containing all the players who will be in the round before you teleport them. Then when they die (using the died event in the humanoid) you can remove them from the table. Heres an example:
_G.players = {}
for _, player in pairs (game.Players:GetPlayers()) do
table.insert(players, player)
end
Then in another script do type this (I'm putting it in another script for organisation):
game.Players.PlayerAdded:connect(function(player)
player.CharacterAdded:connect(function(character)
character.Humanoid.Died:connect(function()
table.remove(_G.players, _G.players[player])
end)
end)
end)
This discussion is preserved as it was. New answers, comments, and votes are closed.
