Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Action activates when all players but 1 die?

So, i can't figure out how this would work.... the title says it all. I have a variable that holds all the players and a killer variable that represents a player that was randomly chosen from the Players variable/table.

Would i use a Died event? IDK!

1 comment

0

By Died event you mean CharacterRemoving.So every time a Player is dead remove their name from the table until you have  one  player name in the table.

2 answers

✓ Accepted answer

Make an alive variable inside the players, and create a separate script to handle switching it off when their Humanoid.Died

Then create a table, like alive = {}

alive = {}
--later in the script
		for i,v in pairs(game.Players:GetPlayers()) do
			if v:FindFirstChild("Alive") then
				v.Alive.Value = true
				table.insert(alive, v.Name)
			end
		end
--this is the part to end it If only one player is alive
		for time = 1,120 do 
			wait(1) 
			if #alive <= 1 then
				break
			end 
			for i,v in pairs(game.Players:GetPlayers()) do 
				if not v.Alive.Value then 
					table.remove(alive, i)
				end 
			end 
		end 

This is just an example of how I do it.

1 comment

0

Inside the Players variable or game.Players?

Yes, you would use a Died event, and the variable that holds the players should be a table. Whenever a player dies, you would remove them from the table, and after a player dies you should check the length of the table that holds the players and see if the length is equal to one, if so, do your action.

This discussion is preserved as it was. New answers, comments, and votes are closed.