|
| 24 Sep 2016 01:02 PM |
This doesn't work, even though I'm sure they have "Alive" inside of them and stuff. No errors. I believe it is because their character is removed before I can do anything.
local alive = game.ServerStorage:WaitForChild("RoundData"):WaitForChild("NumInRound")
game.Players.PlayerRemoving:connect(function(player) local char = player.Character if char ~= nil and char:FindFirstChild("Alive") ~= nil then alive.Value = alive.Value - 1 print("Yay") end end) |
|
|
| Report Abuse |
|
|
vexieh
|
  |
| Joined: 22 Oct 2009 |
| Total Posts: 3468 |
|
|
| 24 Sep 2016 01:06 PM |
Try this
--http://wiki.roblox.com/index.php?title=API:Class/DataModel/OnClose game.OnClose = function() print 'Closing, waiting' wait(3) print 'Done' end
local alive = game.ServerStorage:WaitForChild("RoundData"):WaitForChild("NumInRound")
game.Players.PlayerRemoving:connect(function(player) local char = player.Character if char ~= nil and char:FindFirstChild("Alive") ~= nil then alive.Value = alive.Value - 1 print("Yay") end end)
If it doesn't work then it might be something you're doing
|
|
|
| Report Abuse |
|
|
Monadic
|
  |
| Joined: 03 Aug 2016 |
| Total Posts: 731 |
|
| |
|
iYzarky
|
  |
| Joined: 01 Jun 2009 |
| Total Posts: 1271 |
|
|
| 24 Sep 2016 01:08 PM |
Monadic, you need a life fam.
Cookiez |
|
|
| Report Abuse |
|
|
Monadic
|
  |
| Joined: 03 Aug 2016 |
| Total Posts: 731 |
|
|
| 24 Sep 2016 01:10 PM |
I don't want one. I choose not to socialize with people outside. |
|
|
| Report Abuse |
|
|
vexieh
|
  |
| Joined: 22 Oct 2009 |
| Total Posts: 3468 |
|
| |
|
|
| 24 Sep 2016 01:12 PM |
| Vex, do you care to explain how that will work? |
|
|
| Report Abuse |
|
|
|
| 24 Sep 2016 01:12 PM |
| Neither of them are idiots, he was on the right thinking but in a test server the server doesn't close when the last player leaves so that doesn't matter. @Intended_Pun when the player leaves his character is destroyed what you have should work because player removing should give you enough time to do that. Does it work sometimes? if it does then it could be that players are disconnecting because that wont work if they disconnect, Like if they have bad wifi or if there computer gets unplugged. If it never works try looking for another way of doing it. Why does it matter if the value gets -1 lives, if the player left? |
|
|
| Report Abuse |
|
|
Monadic
|
  |
| Joined: 03 Aug 2016 |
| Total Posts: 731 |
|
| |
|
|
| 24 Sep 2016 01:14 PM |
@Lua It is a round-based game where the last one standing wins, so if a player leaves it is impossible to win. |
|
|
| Report Abuse |
|
|
vexieh
|
  |
| Joined: 22 Oct 2009 |
| Total Posts: 3468 |
|
|
| 24 Sep 2016 01:16 PM |
@Intended_Pun It'll give you more time to save and do stuff with the player before they leave, so if everything in where you believe it is then OnClose should fix your problem.
|
|
|
| Report Abuse |
|
|
|
| 24 Sep 2016 01:18 PM |
| why not just check if the a player leaves remove that player from a table of players in the round(If you have one) or something along those lines? if the player is no longer in the game the script wont be able to access the value anyways. |
|
|
| Report Abuse |
|
|
|
| 24 Sep 2016 01:19 PM |
| That's for when the game shuts down. I want something where their character is not removed until I'm ready for it to be removed. I'm testing in a test server w/ 2 players so the game shutting down too early is not my problem. |
|
|
| Report Abuse |
|
|
|
| 24 Sep 2016 01:19 PM |
@Lua I'm probably going to have to do that :( I wanted to get by with less work but oh well right? |
|
|
| Report Abuse |
|
|
vexieh
|
  |
| Joined: 22 Oct 2009 |
| Total Posts: 3468 |
|
|
| 24 Sep 2016 01:20 PM |
^ The point of OnClose is to stop the player leaving for a few seconds, so they don't leave before you get a chance to do something with all their data
|
|
|
| Report Abuse |
|
|
|
| 24 Sep 2016 01:21 PM |
| @vex, No the point of onclose if for teh server, when all the players leave teh server shuts down, onclose will keep the server open for up to 30 seconds after all the players are gone. |
|
|
| Report Abuse |
|
|
|
| 24 Sep 2016 01:22 PM |
| I'll use the table idea. Thank you Lua. |
|
|
| Report Abuse |
|
|
|
| 24 Sep 2016 01:25 PM |
| Ok no problem but here because you are doing that when a player leaves don't use playerRemoving, use Players.ChildRemoved. The difference is player removing fires when the player is leaving meaning if they shut there computer off or disconnect because of wifi it wont actually fire, ChildRemoved fires when the instance is already gone so it will still fire if anything like that happens and works just like playerremoving. |
|
|
| Report Abuse |
|
|