|
| 17 Jan 2013 07:44 PM |
| I want to be able to toggle it so that it doesn't run all the time. I need it for a section in my game as a failsafe incase the player leaves before something was supposed to happen. |
|
|
| Report Abuse |
|
|
|
| 17 Jan 2013 07:49 PM |
game.Players.PlayerRemoving:connect(function(player) -- player is the Player that is leaving end) |
|
|
| Report Abuse |
|
|
|
| 17 Jan 2013 08:00 PM |
Thank you MeBilly.
So, if this were in a LocalScript within a GUI, and I did this: ------------------------------------------------ p = game.Players.LocalPlayer
game.Players.PlayerRemoving:connect(function(p) print ("goodbye" ..p.Character.Name) end) ------------------------------------------------ It would work? |
|
|
| Report Abuse |
|
|
|
| 17 Jan 2013 08:03 PM |
Probably. I'm not sure about using their character once the event has been triggered. But you can find their name without that. So just to be safe, I'd make it:
p = game.Players.LocalPlayer
game.Players.PlayerRemoving:connect(function(p) print ("goodbye" ..p.Name) end) |
|
|
| Report Abuse |
|
|
|
| 17 Jan 2013 08:08 PM |
| Alright. Thanks a lot, MeBilly. I really appreciate it. |
|
|
| Report Abuse |
|
|
|
| 17 Jan 2013 08:11 PM |
| Hold on. I just thought of something. If I put this script in the player's GUI... wouldn't it not run if he leaves? Since the script is removed when he leaves? |
|
|
| Report Abuse |
|
|
|
| 17 Jan 2013 08:13 PM |
| Well, in theory the player hasn't actually left yet, because the event has been triggered and it's giving your the player. But just to be save, I'd put it in a normal script in Workspace, if you can. |
|
|
| Report Abuse |
|
|
MrNicNac
|
  |
| Joined: 29 Aug 2008 |
| Total Posts: 26567 |
|
|
| 17 Jan 2013 08:15 PM |
| Whatever you do on the PlayerRemoving event when it's in the player's descendants has to be done in one frame. Because the next frame, the script will be destroyed and the code-thread won't exist anymore. |
|
|
| Report Abuse |
|
|
|
| 17 Jan 2013 08:21 PM |
The problem with that is that I need to be able to toggle the script at certain times. It only needs to work when I enable the script. Sorry for all the questions.
I don't actually need the player's name.
So, would it be consistant and safe enough if I just had the LocalScript in a GUI like this?:
p = game.Players.LocalPlayer
game.Players.PlayerRemoving:connect(function(p) game.Workspace.LightheartedLvl2.LevelJump.NxtLvlPort.Disable.Value = false end) |
|
|
| Report Abuse |
|
|
MrNicNac
|
  |
| Joined: 29 Aug 2008 |
| Total Posts: 26567 |
|
|
| 17 Jan 2013 08:21 PM |
| It would be safer to not do it locally. |
|
|
| Report Abuse |
|
|
|
| 17 Jan 2013 08:22 PM |
Do you need the player? If not, then I see no point in putting it in the GUI.
¤ ¤ † K M X D † ¤ ¤ |
|
|
| Report Abuse |
|
|
|
| 17 Jan 2013 08:25 PM |
@ Knightmare
It has to be toggle-able according to what the player did.
So, it would be better just to make it a normal script and have it to something like this?:
p = script.Parent.Parent.Parent
game.Players.PlayerRemoving:connect(function(p) game.Workspace.LightheartedLvl2.LevelJump.NxtLvlPort.Disable.Value = false end) |
|
|
| Report Abuse |
|
|
MrNicNac
|
  |
| Joined: 29 Aug 2008 |
| Total Posts: 26567 |
|
|
| 17 Jan 2013 08:26 PM |
| It would be "safer" for to be in the workspace and not specific to a player's descendants. |
|
|
| Report Abuse |
|
|
| |
|
|
| 17 Jan 2013 08:35 PM |
I suppose. Though in your most recent script, remove the declaration of the variable p. It's not needed.
¤ ¤ † K M X D † ¤ ¤ |
|
|
| Report Abuse |
|
|
| |
|
MrNicNac
|
  |
| Joined: 29 Aug 2008 |
| Total Posts: 26567 |
|
|
| 17 Jan 2013 08:37 PM |
| I'm just thinking the event won't even fire.... |
|
|
| Report Abuse |
|
|
|
| 17 Jan 2013 08:44 PM |
Assuming it's in Workpace, of course. I thought that when you asked if it was safe, you were talking about placing it inside of Workspace.
¤ ¤ † K M X D † ¤ ¤ |
|
|
| Report Abuse |
|
|
|
| 17 Jan 2013 08:50 PM |
Ran with Tools -> Test -> Start Server & Tools -> Test -> Start Player One script in Workspace: game.Players.PlayerRemoving:connect(function(player) Instance.new("Message", game.Workspace).Text = player.Name.." left!" end) One LocalScript in StarterPack: game.Players.PlayerRemoving:connect(function(player) Instance.new("Part", game.Workspace).Anchored = true end)
> Leave with Player1 >> New message in Workspace, no new brick
Why didn't I just do that before posting? qq |
|
|
| Report Abuse |
|
|