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
 

Re: Get player's character when they leave

Previous Thread :: Next Thread 
Intended_Pun is not online. Intended_Pun
Joined: 10 Aug 2016
Total Posts: 4384
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 is not online. 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 is not online. Monadic
Joined: 03 Aug 2016
Total Posts: 731
24 Sep 2016 01:07 PM
what an idiot
Report Abuse
iYzarky is not online. iYzarky
Joined: 01 Jun 2009
Total Posts: 1271
24 Sep 2016 01:08 PM
Monadic, you need a life fam.


Cookiez
Report Abuse
Monadic is not online. 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 is not online. vexieh
Joined: 22 Oct 2009
Total Posts: 3468
24 Sep 2016 01:11 PM
savage


Report Abuse
Intended_Pun is not online. Intended_Pun
Joined: 10 Aug 2016
Total Posts: 4384
24 Sep 2016 01:12 PM
Vex, do you care to explain how that will work?
Report Abuse
LuaDeveloped is not online. LuaDeveloped
Joined: 28 Jan 2016
Total Posts: 439
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 is not online. Monadic
Joined: 03 Aug 2016
Total Posts: 731
24 Sep 2016 01:13 PM
^ Trying this hard
Report Abuse
Intended_Pun is not online. Intended_Pun
Joined: 10 Aug 2016
Total Posts: 4384
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 is not online. 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
LuaDeveloped is not online. LuaDeveloped
Joined: 28 Jan 2016
Total Posts: 439
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
Intended_Pun is not online. Intended_Pun
Joined: 10 Aug 2016
Total Posts: 4384
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
Intended_Pun is not online. Intended_Pun
Joined: 10 Aug 2016
Total Posts: 4384
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 is not online. 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
LuaDeveloped is not online. LuaDeveloped
Joined: 28 Jan 2016
Total Posts: 439
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
Intended_Pun is not online. Intended_Pun
Joined: 10 Aug 2016
Total Posts: 4384
24 Sep 2016 01:22 PM
I'll use the table idea. Thank you Lua.
Report Abuse
LuaDeveloped is not online. LuaDeveloped
Joined: 28 Jan 2016
Total Posts: 439
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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
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