|
| 04 Aug 2016 11:21 PM |
I'm lost on how I would end a game if all players die. I know have I have to make a table, but I'm still confused.
|
|
|
| Report Abuse |
|
|
Laedere
|
  |
| Joined: 17 Jun 2013 |
| Total Posts: 23601 |
|
|
| 04 Aug 2016 11:22 PM |
after a person dies store their name in the table if the table length is equal to the amount of players in the game then everyone is dead
|
|
|
| Report Abuse |
|
|
|
| 04 Aug 2016 11:24 PM |
Im new to scripting, still confused.
|
|
|
| Report Abuse |
|
|
Soybeen
|
  |
| Joined: 17 Feb 2010 |
| Total Posts: 21462 |
|
|
| 04 Aug 2016 11:24 PM |
^ Make sure that if they die twice (assuming that's possible) you don't add their name twice.
|
|
|
| Report Abuse |
|
|
|
| 04 Aug 2016 11:26 PM |
hmm so how would I actually script if they die? and what if someone joins in the middle of the round and resets.
|
|
|
| Report Abuse |
|
|
Kodran
|
  |
| Joined: 15 Aug 2013 |
| Total Posts: 5330 |
|
|
| 04 Aug 2016 11:27 PM |
Well the humanoid has an event called Died which fires whenever that humanoid dies. You'll want to make a table of all the players in the game using the GetPlayers method, then when one of them dies remove them from the table until nobody remains. Here's just a small example of what you're looking for:
local myPlayers = game.Players:GetPlayers() --set myPlayers to a table of all players
for i,v in pairs(myPlayers) do --for each player if v.Character then --if they have a character (just in case) v.Character.Humanoid.Died:connect(function() -- when they die table.remove(myPlayers, i) --remove them from the table if #myPlayers == 0 then --if there are no more players then print'THEYRE ALL DEAD!' end end) end end |
|
|
| Report Abuse |
|
|
Kodran
|
  |
| Joined: 15 Aug 2013 |
| Total Posts: 5330 |
|
|
| 04 Aug 2016 11:28 PM |
| Having a table at the start and removing them is better because it doesn't get messed up by people that join halfway through, it entirely ignores them. If you want to add people who join you'll have to use some other method. |
|
|
| Report Abuse |
|
|
|
| 04 Aug 2016 11:30 PM |
Thanks so much I appreciate it. I want it to ignore people who join, so thats good.
|
|
|
| Report Abuse |
|
|
|
| 04 Aug 2016 11:30 PM |
Also, so I need to script is the actual game ending? which shouldn't be too hard.
|
|
|
| Report Abuse |
|
|
Kodran
|
  |
| Joined: 15 Aug 2013 |
| Total Posts: 5330 |
|
|
| 04 Aug 2016 11:38 PM |
| yeah where I print 'THEYRE ALL DEAD' just put what you want to happen when all players are dead. Keep in mind I haven't tested the script so they're could be errors I just overlooked. |
|
|
| Report Abuse |
|
|
|
| 04 Aug 2016 11:38 PM |
Hmm let's say someone was in the round playing ,then decide to leave. Then all players die besides one. Wouldn't the game reset then? How would I fix this glitch,
|
|
|
| Report Abuse |
|
|
Kodran
|
  |
| Joined: 15 Aug 2013 |
| Total Posts: 5330 |
|
|
| 04 Aug 2016 11:41 PM |
This will go after the other stuff, just removes them from the table if they leave.
game.Players.PlayerRemoving:connect(function(p) for i,v in pairs(myPlayers) do if v == p then table.remove(myPlayers, i) if #myPlayers == 0 then print'oops the last player left' end end end end) |
|
|
| Report Abuse |
|
|
| |
|
|
| 05 Aug 2016 12:23 AM |
hmm I tested it and it doesnt reset if theres two players. only one.
|
|
|
| Report Abuse |
|
|
Kodran
|
  |
| Joined: 15 Aug 2013 |
| Total Posts: 5330 |
|
|
| 05 Aug 2016 12:23 AM |
| What's your script. Mine should only be used when you want the game to start. |
|
|
| Report Abuse |
|
|
|
| 05 Aug 2016 12:25 AM |
I put it before the players spawn in the map. hm
|
|
|
| Report Abuse |
|
|