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: game.OnClose saving with spawn() versus not

Previous Thread :: Next Thread 
Nulerite is not online. Nulerite
Joined: 08 Mar 2016
Total Posts: 231
12 Mar 2016 11:54 AM
game.OnClose = function()
for _, player in pairs(game.Players:GetPlayers()) do
spawn(function()
saveData(player)
end)
end
end

vs.

game.OnClose = function()
for _, player in pairs(game.Players:GetPlayers()) do
saveData(player)
end
end

I have not seen a definitive answer on whether or not saving data with a new thread will actually save faster. Will it?


Report Abuse
KLGA is not online. KLGA
Joined: 19 Apr 2014
Total Posts: 2571
12 Mar 2016 12:04 PM
I'm assuming it'd be faster with using spawn. Instead of running each function one after another, they are all run simultaneously.
Report Abuse
Fabunil is not online. Fabunil
Joined: 25 Oct 2013
Total Posts: 4325
12 Mar 2016 12:08 PM
Unless the saving methods yield the thread until they are fully executed I would say no.
Report Abuse
ray_revenge is not online. ray_revenge
Joined: 18 Feb 2011
Total Posts: 453
12 Mar 2016 12:09 PM
when OnClose is invoked there will be no players in game
just make OnClose yield for a bit while saving with PlayerRemoving


Recommended username: ToughRay_revenge


Report Abuse
DivinePheonix is not online. DivinePheonix
Joined: 30 Mar 2011
Total Posts: 11190
12 Mar 2016 12:32 PM
game.OnClose = function()
for _, player in pairs(game.Players:GetPlayers()) do
spawn(function()
saveData(player)
end)
end
wait(30)
end
Report Abuse
Nulerite is not online. Nulerite
Joined: 08 Mar 2016
Total Posts: 231
12 Mar 2016 12:48 PM
Why the wait(30)...why on earth would you add a wait(30)...which wouldn't even get to complete.


Report Abuse
Fabunil is not online. Fabunil
Joined: 25 Oct 2013
Total Posts: 4325
12 Mar 2016 05:11 PM
^Without the wait(30) the function might end early and the game would shut down before the saves are completed.
Report Abuse
chimmihc is not online. chimmihc
Joined: 01 Sep 2014
Total Posts: 17143
12 Mar 2016 05:25 PM
Roblox "threads" don't "run simultaneously", only one is running at a time, use the second option.


Report Abuse
eLunate is not online. eLunate
Joined: 29 Jul 2014
Total Posts: 13268
12 Mar 2016 05:27 PM
Spawn doesn't start a new thread. In fact, using spawn() in this situation is counterintuitive.
Report Abuse
Nulerite is not online. Nulerite
Joined: 08 Mar 2016
Total Posts: 231
12 Mar 2016 07:41 PM
Oh I forgot he was calling spawn() in there so yeah it would


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