Elandorr
|
  |
| Joined: 25 Sep 2015 |
| Total Posts: 148 |
|
|
| 30 Sep 2015 07:25 PM |
| whats the most effiecent way to check if players die? |
|
|
| Report Abuse |
|
|
|
| 30 Sep 2015 07:27 PM |
You hook up to the Humanoids .Died event.
game:GetService("Players").PlayerAdded:connect(function(player) player.CharacterAdded:connect(function(char) char:WaitForChild("Humanoid").Died:connect(function() print(player.Name .. " just died :(") end) end) end)
morashsPeasant is eating |
|
|
| Report Abuse |
|
|
Elandorr
|
  |
| Joined: 25 Sep 2015 |
| Total Posts: 148 |
|
|
| 30 Sep 2015 07:28 PM |
does the .Died event always run? like its the same as if u went while wait() do if humanoid.Health == 0 then end end |
|
|
| Report Abuse |
|
|
rayk999
|
  |
| Joined: 18 Feb 2011 |
| Total Posts: 4705 |
|
| |
|
Elandorr
|
  |
| Joined: 25 Sep 2015 |
| Total Posts: 148 |
|
|
| 30 Sep 2015 07:29 PM |
| So then will it only check once if there dead? |
|
|
| Report Abuse |
|
|
rayk999
|
  |
| Joined: 18 Feb 2011 |
| Total Posts: 4705 |
|
| |
|
|
| 30 Sep 2015 07:31 PM |
i want the banhammer so bad
this forum would be worth foruming on
Instance.new("BodyThrust" , Illegallyblind.Pelvis) |
|
|
| Report Abuse |
|
|
|
| 30 Sep 2015 07:32 PM |
.Died() is an event, which means ROBLOX will trigger that function when someone dies, it is not a continuous loop.
-The [Guy] |
|
|
| Report Abuse |
|
|
Elandorr
|
  |
| Joined: 25 Sep 2015 |
| Total Posts: 148 |
|
|
| 30 Sep 2015 07:33 PM |
@rayk, oh yea forgot about that.
@Illegal, D= .. whoo. who is the hammer for? |
|
|
| Report Abuse |
|
|
litalela
|
  |
| Joined: 30 Mar 2010 |
| Total Posts: 6267 |
|
|
| 30 Sep 2015 07:33 PM |
busy its not .Died()
what are you saying
➳Lɪᴛᴀʟᴇʟᴀ ɪs ᴍʏ ɴᴀᴍᴇ, Lᴜᴀ ɪs ᴍʏ ɢᴀᴍᴇツ |
|
|
| Report Abuse |
|
|
|
| 30 Sep 2015 07:34 PM |
Think of it like this: When a player dies their humanoid fires and event saying "Hey I just died" which in case is the Humanoid.Died event. Now every time that event is fired we need to listen to it and run a function which we do by saying ".Died:connect(function() ....)
However everytime a player dies they get a new humanoid, so listening to the old humanoids .Died event would be no good.. since that connection would be destroyed, so we have to attach a new listener everytime the player gets a new humanoid.
And finally to answer your question, YES :D
morashsPeasant is dancing |
|
|
| Report Abuse |
|
|
|
| 30 Sep 2015 07:34 PM |
Lol sorry I wasn't thinking, I was just typing.
.Died that's all that's what I meant
k thanks
-The [Guy] |
|
|
| Report Abuse |
|
|
Elandorr
|
  |
| Joined: 25 Sep 2015 |
| Total Posts: 148 |
|
|
| 30 Sep 2015 07:39 PM |
Ok well, anyway. What im trying to get it to do isnt working heres the code: Nothing is printing and im testing it with 3 fake players
game:GetService("Players").PlayerAdded:connect(function(isDeadPlayer) isDeadPlayer.CharacterAdded:connect(function(char) char:WaitForChild("Humanoid").Died:connect(function() for i,v in pairs(playersInRound) do if v.Name == isDeadPlayer.Name then table.remove(playersInRound, i) print(playersInRound[2]) end end end) end) end) repeat wait() until playersInRound == {} print("Game Over") |
|
|
| Report Abuse |
|
|
|
| 30 Sep 2015 07:41 PM |
Is your playersInRound table empty? And also note that order DOES matter here, once you remove something from a table, you can't go back and refrence it since its alreay gone! Try this:
for i,v in pairs(playersInRound) do if v.Name == isDeadPlayer.Name then table.remove(playersInRound, i) print(isDeadPlayer.Name) return end end
morashsPeasant is standing |
|
|
| Report Abuse |
|
|
Elandorr
|
  |
| Joined: 25 Sep 2015 |
| Total Posts: 148 |
|
|
| 30 Sep 2015 07:47 PM |
| There is stuff still in Table, but your code didnt work, |
|
|
| Report Abuse |
|
|
|
| 30 Sep 2015 07:49 PM |
Also be careful with the way you keep track of this, because if a player leaves or crashes or something in the middle of a round, you need to update your table.
Your code looked fine, I don't know what the issue is.
-The [Guy] |
|
|
| Report Abuse |
|
|
Elandorr
|
  |
| Joined: 25 Sep 2015 |
| Total Posts: 148 |
|
|
| 30 Sep 2015 07:50 PM |
ok, its not printing anything when he dies, so its something to do with the
game:GetService("Players").PlayerAdded:connect(function(isDeadPlayer) isDeadPlayer.CharacterAdded:connect(function(char) char:WaitForChild("Humanoid").Died:connect(function() |
|
|
| Report Abuse |
|
|
Elandorr
|
  |
| Joined: 25 Sep 2015 |
| Total Posts: 148 |
|
|
| 30 Sep 2015 07:51 PM |
| @Busy, yup im gonna add a playerRemoved event to remove |
|
|
| Report Abuse |
|
|
|
| 30 Sep 2015 07:53 PM |
Oh put that at the top of your script.
morashsPeasant is skrubbing |
|
|
| Report Abuse |
|
|
|
| 30 Sep 2015 07:54 PM |
Open a test server and try it in studio. Not Solo Mode
morashsPeasant is praising Dermon |
|
|
| Report Abuse |
|
|
Elandorr
|
  |
| Joined: 25 Sep 2015 |
| Total Posts: 148 |
|
|
| 30 Sep 2015 07:57 PM |
| everything ive been testing is in server mode |
|
|
| Report Abuse |
|
|
|
| 30 Sep 2015 07:59 PM |
Oh, I'm not sure whats wrong, try looking at some free models.. Here is the event you'd connect to: http://wiki.roblox.com/index.php?title=API:Class/Humanoid/Died
morashsPeasant is eating |
|
|
| Report Abuse |
|
|
Elandorr
|
  |
| Joined: 25 Sep 2015 |
| Total Posts: 148 |
|
|
| 30 Sep 2015 08:01 PM |
no no its working now, the died part. But its not recognizing this part, its waiting but not the until part. The table is empty i did print(playersInRound[1]) and there is nothing there so yea.
repeat wait() until playersInRound == {} print("Game Over") |
|
|
| Report Abuse |
|
|
Elandorr
|
  |
| Joined: 25 Sep 2015 |
| Total Posts: 148 |
|
|
| 30 Sep 2015 08:04 PM |
Got it! There will always be a table[1] right unless table is empty right? Well I did until playersInRound[1] == nil worked! |
|
|
| Report Abuse |
|
|
|
| 30 Sep 2015 08:06 PM |
Yes, table.remove will bump all the values up to fill the gap if the first one is removed for example. It's kind of a sketchy way to handle things, I feel like there is a simpler way to do all this, but if it works for you then it works I guess.
-The [Guy] |
|
|
| Report Abuse |
|
|