|
| 04 May 2013 08:49 PM |
So I have a function that saves a bunch of data persistence values when a player leaves. It works just fine when I call it while the player is there, but when I use it as a player leaves, it doesn't work.
It seemed to work when other players are there, rather than when it's only me testing. I think it may have to do with the server shutting down before the script has finished saving the values. How would I fix that? |
|
|
| Report Abuse |
|
|
| |
|
chris1989
|
  |
| Joined: 30 Nov 2007 |
| Total Posts: 2520 |
|
|
| 04 May 2013 08:54 PM |
| Save on changed or auto save every few minutes or seconds |
|
|
| Report Abuse |
|
|
|
| 04 May 2013 08:55 PM |
I would use the changed event on the leaderstats and save it when it changes.
Ex:
Save = function() --Save All Stats end
for _,n in next,Player.leaderstats:GetChildren() do n.Changed:connect(Save) end |
|
|
| Report Abuse |
|
|
|
| 04 May 2013 08:56 PM |
| I completely forgot that I did with metatables for my game :I |
|
|
| Report Abuse |
|
|
|
| 04 May 2013 08:58 PM |
| Yeah, I was hoping to get to a solution without periodic saves, but it looks like it's the only answer. |
|
|
| Report Abuse |
|
|
|
| 04 May 2013 08:59 PM |
| So you're just going to ignore the suggestions that solve your problem? |
|
|
| Report Abuse |
|
|
chris1989
|
  |
| Joined: 30 Nov 2007 |
| Total Posts: 2520 |
|
|
| 04 May 2013 09:00 PM |
| Are you useing values in the player or a global table full of variables? |
|
|
| Report Abuse |
|
|
|
| 04 May 2013 09:03 PM |
@Chris: In the player's backpack, but I clone it before I fetch and save, so it doesn't turn nil while I save
@MonkeyMan: Not at all. Periodic saves were suggested, and they'll probably be a bit less intensive than a connection to Changed, since some of these stats will be in constant flux. |
|
|
| Report Abuse |
|
|
|
| 04 May 2013 09:05 PM |
| Unless you're planning to change the values 30 times per second, connections (or metatables) would be the best way to go. |
|
|
| Report Abuse |
|
|
|
| 04 May 2013 09:08 PM |
| I'll go with connections, then, since I have yet to teach myself metatables. Thank you all. |
|
|
| Report Abuse |
|
|