generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: Ending Game On All Players Dead

Previous Thread :: Next Thread 
harbar565 is not online. harbar565
Joined: 05 Nov 2010
Total Posts: 67
29 Jan 2012 01:33 PM
Hey I was making a script for a MW3 Type survival game, and I got 50 waves set up than realized I need a way for the game to end when all the players are dead. What I have now is that they are teleported down to the map and when the game ends they die and get teleported back to spawn which isn't very good because there is no point to the game. Is there another way for the game to end when all players die?
Report Abuse
Alexrocksdude is not online. Alexrocksdude
Joined: 19 Jan 2011
Total Posts: 3828
29 Jan 2012 01:34 PM
while true do
end
Report Abuse
harbar565 is not online. harbar565
Joined: 05 Nov 2010
Total Posts: 67
29 Jan 2012 01:35 PM
Umm.. no that wouldn't do anything right? I started it with:


while true do

and ended with


end
end
Report Abuse
darkkiller5555 is not online. darkkiller5555
Joined: 22 Nov 2009
Total Posts: 6359
29 Jan 2012 01:36 PM
Yes.

First, get all the players. Insert them into a table. Then, when a player dies, remove them from the table. When the table has no values inside of it, the game ends.

Here's a list of things you'll need.

:GetPlayers()
Table manipulation
.Died

And that's about it.
Report Abuse
harbar565 is not online. harbar565
Joined: 05 Nov 2010
Total Posts: 67
29 Jan 2012 01:38 PM
Ok... do you know where I could go get information on tables? I just started the whole scripting thing :C
Report Abuse
harbar565 is not online. harbar565
Joined: 05 Nov 2010
Total Posts: 67
29 Jan 2012 01:42 PM
would the wiki be any help?
Report Abuse
AgentFirefox is not online. AgentFirefox
Top 100 Poster
Joined: 20 Jun 2008
Total Posts: 22404
29 Jan 2012 01:46 PM
For something this complicated? Nah. I'll write something up for you real fast.
Report Abuse
harbar565 is not online. harbar565
Joined: 05 Nov 2010
Total Posts: 67
29 Jan 2012 01:52 PM
Ty :D
Report Abuse
AgentFirefox is not online. AgentFirefox
Top 100 Poster
Joined: 20 Jun 2008
Total Posts: 22404
29 Jan 2012 01:53 PM
local Alive = {}
local GameActive = false

function PlayerDied(Player)
    if Alive[Player.Name] then
        Alive[Player.Name] = false
    end
end

function SetPlayersAlive()
    for _, v in pairs(game.Players:GetPlayers()) do
        if v.Character and v.Character:FindFirstChild("Humanoid") and not GameActive then
            Alive[v.Name] = true
            v.Character.Humanoid.Died:connect(function() PlayerDied(v) end)
        end
    end
end

function AllPlayersDead()
    for _, v in pairs(Alive) do
        if v then return false end
    end
    return true
end

game.Players.PlayerRemoving:connect(function(player)
    PlayerDied(player)
end)



Basically, we have a function that runs when a player dies. This function sets the value at the player's name in the table to false. When you run the SetPlayersAlive function, you add all eligible players to the Alive table. The AllPlayersDead function checks to see if all the players have died. We use the PlayerRemoving event to determine that a player has died as well, in case they leave the game in the middle of the match.

Basic table manipulation is all that was really needed.
Report Abuse
harbar565 is not online. harbar565
Joined: 05 Nov 2010
Total Posts: 67
29 Jan 2012 01:56 PM
So this script will make it so when the game starts and all online players get teleported to the spawn location i set it will add all alive players? And once they all die the script will end?
Report Abuse
harbar565 is not online. harbar565
Joined: 05 Nov 2010
Total Posts: 67
29 Jan 2012 01:57 PM
Where in a script would i add this? And how would I set what it would end?
Report Abuse
AgentFirefox is not online. AgentFirefox
Top 100 Poster
Joined: 20 Jun 2008
Total Posts: 22404
29 Jan 2012 01:58 PM
Simply call the function SetPlayersAlive after you teleport them, then call the function AllPlayersDead function to see if all the players have died.



-- teleport players
SetPlayersAlive()
repeat wait() until AllPlayersDead()
-- EXAMPLE CODE
Report Abuse
harbar565 is not online. harbar565
Joined: 05 Nov 2010
Total Posts: 67
29 Jan 2012 02:00 PM
ok so the


repeat wait() until AllPlayersDead()

will constantly check to see if all the players are dead and start my whole script back up to the point where

while true do

started it?
Report Abuse
harbar565 is not online. harbar565
Joined: 05 Nov 2010
Total Posts: 67
29 Jan 2012 02:04 PM
right?
Report Abuse
AgentFirefox is not online. AgentFirefox
Top 100 Poster
Joined: 20 Jun 2008
Total Posts: 22404
29 Jan 2012 02:04 PM
If that's the end of the while loop, then yes.
Basically, the script will pause at that point, then continue on after all the players die.
Report Abuse
harbar565 is not online. harbar565
Joined: 05 Nov 2010
Total Posts: 67
29 Jan 2012 02:05 PM
ok ty :D
Report Abuse
KC9KVU is not online. KC9KVU
Joined: 10 Sep 2008
Total Posts: 821
29 Jan 2012 02:37 PM
I am working on a script that I need something very similar to this, but I need to end the game on all but one players dead. I was wondering if somebody could help me and show me the difference in the two scripts.
Report Abuse
KC9KVU is not online. KC9KVU
Joined: 10 Sep 2008
Total Posts: 821
29 Jan 2012 03:07 PM
And I also would like it to be able to say who was the last one left. If anybody could do this that would be AMAZING.

Thanks,
KC
Report Abuse
KC9KVU is not online. KC9KVU
Joined: 10 Sep 2008
Total Posts: 821
29 Jan 2012 03:58 PM
Anybody?
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image