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: Another question about BindToClose()

Previous Thread :: Next Thread 
Intended_Pun is not online. Intended_Pun
Joined: 10 Aug 2016
Total Posts: 4384
18 Feb 2017 02:21 PM
So could I use it like this? There's precious little info on the wiki, sorry.

function save()
--Save data
end

game:BindToClose(save)

--Then, can I just call the function like normal?

game.Players.PlayerRemoving:connect(function()
save()
end)
Report Abuse
Lua_Basics is not online. Lua_Basics
Joined: 04 Jun 2012
Total Posts: 9977
18 Feb 2017 02:23 PM
I'd just loop through the players and save all the Data, as this holds the game from closing but it will close. So go through and save all the data then wait() to close the game, as it will allow for it to correctly save.
Report Abuse
mister1nothing is not online. mister1nothing
Joined: 27 Dec 2007
Total Posts: 579
18 Feb 2017 02:26 PM
PlayerRemoving is called after the player's already left. BindToClose is called when the player clicks the X button.

essentially, PlayerRemoving is for the client, and BindToClose is for the server. Since you're calling both you're saving the data twice.


Report Abuse
mister1nothing is not online. mister1nothing
Joined: 27 Dec 2007
Total Posts: 579
18 Feb 2017 02:26 PM
Er, reverse my last post. PlayerRemoving is for the Server and BindToClose is for the Client.


Report Abuse
Intended_Pun is not online. Intended_Pun
Joined: 10 Aug 2016
Total Posts: 4384
18 Feb 2017 02:29 PM
I'm 99% sure BindToClose() is a function that binds a function to run, and ### game does not close until that function is done. PlayerRemoving() is fired when a player leaves ### game. Thanks for ### help anyway.
Report Abuse
mister1nothing is not online. mister1nothing
Joined: 27 Dec 2007
Total Posts: 579
18 Feb 2017 02:31 PM
Yes, you're correct. But if you're calling save() in both function...


First, the player closes the game, which triggers BindToClose and runs save().

Then, the server gets notified that the player is leaving and starts PlayerRemoving(). Since you've bound save to PlayerRemoving, save() is run a second time and the data is saved again, possibly incompletely.


Report Abuse
foreverpower is not online. foreverpower
Joined: 05 Feb 2011
Total Posts: 5578
18 Feb 2017 02:33 PM
@mister1nothing

What are you even talking about? BindToClose is when the server shuts down, playerleaving is when a player leaves.


Report Abuse
Intended_Pun is not online. Intended_Pun
Joined: 10 Aug 2016
Total Posts: 4384
18 Feb 2017 02:35 PM
So then what should I do to just make it so ### game doesn't shut down until their data saves? Add this to ### script that saves?: game:BindToClose:connect(function() wait(30) end)
Report Abuse
Intended_Pun is not online. Intended_Pun
Joined: 10 Aug 2016
Total Posts: 4384
18 Feb 2017 02:35 PM
Roblox loves filtering "the".
Report Abuse
ForestTrooper263I is not online. ForestTrooper263I
Joined: 24 Dec 2008
Total Posts: 38
18 Feb 2017 02:37 PM
void BindToClose (
function function
)

it takes in a function

so yes you can do that


Report Abuse
mister1nothing is not online. mister1nothing
Joined: 27 Dec 2007
Total Posts: 579
18 Feb 2017 02:38 PM
Um. What? Yeah ### filter's a little overbearing. Anyway, I was mistaken, I thought BindToClose was a clientside function. Rereading ### devforum I see it's a server-side function now. It'd be easier to just do game.BindToClose(function(save() wait(30));
Report Abuse
Intended_Pun is not online. Intended_Pun
Joined: 10 Aug 2016
Total Posts: 4384
18 Feb 2017 02:50 PM
Ok thanks forest.
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