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 » Scripters
Home Search
 

Please help!

Previous Thread :: Next Thread 
kungzupanda is not online. kungzupanda
Joined: 20 Aug 2011
Total Posts: 183
05 Aug 2016 02:20 AM
Okay so it prints all players have died if there is only one player testing, but with two players #myPlayers stays 1 even if they both die. Help? Thanks

local myPlayers = game.Players:GetPlayers()

for i,v in pairs(myPlayers) do --for each player
if v.Character then
v.Character.Humanoid.Died:connect(function()
table.remove(myPlayers, i)
if #myPlayers == 0 then
print('All players have died!')
end
end)
end
end



Report Abuse
Obbay2 is not online. Obbay2
Joined: 23 Aug 2008
Total Posts: 51
05 Aug 2016 02:38 AM
table.remove shifts all values in the table when used. So to your second part if the "first" player dies first, there won't be any player at index 2 to remove.

As to why only one player causes the print I'm not sure.
Report Abuse
kungzupanda is not online. kungzupanda
Joined: 20 Aug 2011
Total Posts: 183
05 Aug 2016 02:51 AM
Oh okay, what should I use instead?


Report Abuse
kungzupanda is not online. kungzupanda
Joined: 20 Aug 2011
Total Posts: 183
05 Aug 2016 11:27 AM
hmm


Report Abuse
kungzupanda is not online. kungzupanda
Joined: 20 Aug 2011
Total Posts: 183
05 Aug 2016 11:34 AM
b1


Report Abuse
kungzupanda is not online. kungzupanda
Joined: 20 Aug 2011
Total Posts: 183
05 Aug 2016 11:38 AM
So obviously the table.remove is the problem, does anyone know what else I could use?


Report Abuse
YoBoiDevDerpy is not online. YoBoiDevDerpy
Joined: 05 Feb 2011
Total Posts: 3020
05 Aug 2016 11:38 AM
Wiki?
I dunno tbh XD
Report Abuse
kungzupanda is not online. kungzupanda
Joined: 20 Aug 2011
Total Posts: 183
05 Aug 2016 11:41 AM
Yeah that's what I thought, I looked and there's nothing on tables that would help me with this. I wrote the whole script from reading the wiki and understanding it, but obviously I don't understand the table.remove part.


Report Abuse
kungzupanda is not online. kungzupanda
Joined: 20 Aug 2011
Total Posts: 183
05 Aug 2016 11:47 AM
hm


Report Abuse
kungzupanda is not online. kungzupanda
Joined: 20 Aug 2011
Total Posts: 183
05 Aug 2016 12:20 PM
anyone?


Report Abuse
thedailyblarg is not online. thedailyblarg
Joined: 26 Feb 2012
Total Posts: 5506
05 Aug 2016 12:21 PM
Well duh. You only use 1 loop which means they only die once and it counts them one time
Report Abuse
kungzupanda is not online. kungzupanda
Joined: 20 Aug 2011
Total Posts: 183
05 Aug 2016 12:23 PM
Do you know how I could fix it?


Report Abuse
thedailyblarg is not online. thedailyblarg
Joined: 26 Feb 2012
Total Posts: 5506
05 Aug 2016 12:25 PM
use CharacterAdded for each player when they join and then Died
Report Abuse
kungzupanda is not online. kungzupanda
Joined: 20 Aug 2011
Total Posts: 183
05 Aug 2016 12:28 PM
Still kinda confused, something like this?

local myPlayers = game.Players:GetPlayers()

for i,v in pairs(myPlayers) do --for each player
if v.Character then
--CharacterAdded
v.Character.Humanoid.Died:connect(function()
table.remove(myPlayers, i)
if #myPlayers == 0 then
print('All players have died!')
end
end)
end
end




Report Abuse
thedailyblarg is not online. thedailyblarg
Joined: 26 Feb 2012
Total Posts: 5506
05 Aug 2016 12:30 PM
Read it in english, does that make sense?

For each player, if they have a character, when they die, connect function

you want:

when a player is added, when their character is added, when they die, connect function
Report Abuse
kungzupanda is not online. kungzupanda
Joined: 20 Aug 2011
Total Posts: 183
05 Aug 2016 12:32 PM
Alright thanks


Report Abuse
kungzupanda is not online. kungzupanda
Joined: 20 Aug 2011
Total Posts: 183
05 Aug 2016 01:11 PM
Hm still doesnt end the game

for i,v in pairs(myPlayers) do --for each player
--game.Players.PlayerAdded:connect(function(player)
game.Players.PlayerAdded:connect(function(player)
player.CharacterAdded:connect(function(character)
if v.Character then --if they have a character
v.Character.Humanoid.Died:connect(function()
table.remove(myPlayers, i)
if #myPlayers == 0 then
game.Workspace.Map.EndGame.Value = true
end
end)
end
end)
end)
end


Report Abuse
kungzupanda is not online. kungzupanda
Joined: 20 Aug 2011
Total Posts: 183
05 Aug 2016 01:21 PM
>when a player is added, when their character is added, when they die, connect function



Report Abuse
thedailyblarg is not online. thedailyblarg
Joined: 26 Feb 2012
Total Posts: 5506
05 Aug 2016 01:23 PM
game.Players.PlayerAdded:connect(function(p)
p.CharacterAdded:connect(function(c)
c:WaitForChild("Humanoid").Died:connect(function()
print( "rip " .. p.Name )
end)
end)
end)


Very easy
Report Abuse
kungzupanda is not online. kungzupanda
Joined: 20 Aug 2011
Total Posts: 183
05 Aug 2016 01:35 PM
hmm nothing prints.


Report Abuse
Kodran is not online. Kodran
Joined: 15 Aug 2013
Total Posts: 5330
05 Aug 2016 01:37 PM
That's not what he's asking for ^^

He wants it so it starts a game with all players in the server, then when one of them dies it removes them until there's nobody left. Something like this:

function startGame()
local plrs = {}
for i,v in pairs(game.Players:GetPlayers()) do
plrs[v.Name] = v
local dieded
dieded = v.Character.Humanoid.Died:connect(function()
plrs[v.Name] = nil
dieded:disconnect()
if #plrs == 0 then
print 'uh oh every1 dieded'
end
end)
end
end
Report Abuse
kungzupanda is not online. kungzupanda
Joined: 20 Aug 2011
Total Posts: 183
05 Aug 2016 01:42 PM
@kodran
Thanks that helped alot!


Report Abuse
kungzupanda is not online. kungzupanda
Joined: 20 Aug 2011
Total Posts: 183
05 Aug 2016 01:45 PM
@kodran
Im trying to solve it, but if theres two players in the game and if one resets the game ends. Hm


Report Abuse
kungzupanda is not online. kungzupanda
Joined: 20 Aug 2011
Total Posts: 183
05 Aug 2016 01:50 PM
Do I need to combine what both of you guys said?


Report Abuse
kungzupanda is not online. kungzupanda
Joined: 20 Aug 2011
Total Posts: 183
05 Aug 2016 02:11 PM
It works perfectly with one player. It ends the game and all. however with two people if only one player resets, the game ends even though one player is still alive


Report Abuse
Previous Thread :: Next Thread 
Page 1 of 2Go to page: [1], 2 Next
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • 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