|
| 12 Oct 2015 05:00 PM |
In my game I use this data store script to save data:
local ds = game:GetService("DataStoreService"):GetDataStore("stats") stats={"variousstats"} --The real script has many values here I just shortened it. game.Players.PlayerAdded:connect(function(plyr) local a=Instance.new("IntValue") a.Parent=plyr a.Name="saves" for i=1,#stats do local stat=Instance.new("IntValue") stat.Parent=a stat.Value=0 stat.Name=stats[i] end local child=plyr.saves:GetChildren() for i=1, #child do child[i].Value=ds:GetAsync(plyr.userId..child[i].Name) end end)
game.Players.PlayerRemoving:connect(function(plyr) local child=plyr.saves:GetChildren() for i=1, #child do child[i].Value=ds:SetAsync(plyr.userId..child[i].Name,child[i].Value) end end)
Most of the time it works fine but occasionally it won't work properly and the player will lose all of their data which can be very annoying. What did I do wrong? |
|
|
| Report Abuse |
|
|
Locard
|
  |
| Joined: 13 Apr 2014 |
| Total Posts: 3516 |
|
|
| 12 Oct 2015 05:02 PM |
| Make sure that you delay the closing of a server (using the OnClose event of game) so that everyone's data will save before the server shuts down. |
|
|
| Report Abuse |
|
|
Dogejia
|
  |
| Joined: 08 Feb 2012 |
| Total Posts: 1873 |
|
|
| 12 Oct 2015 05:04 PM |
I never used datastats, and tried to use it, but everytime I failed, so I'm gonna wait here for good explanations :)
gcmi lg lpxtlc; Decode it with Vigenere Cipher, keyword is Doge, if you dare >:) |
|
|
| Report Abuse |
|
|
KingJacko
|
  |
| Joined: 20 Jun 2008 |
| Total Posts: 3944 |
|
|
| 12 Oct 2015 05:06 PM |
| it is better to save when a value changes, so you wont have to deal with the server closing if thats your problem. |
|
|
| Report Abuse |
|
|
|
| 12 Oct 2015 05:08 PM |
| I have another script that does that (it seems inefficient but I made the save system a while ago and I didn't know how to use that type of function back then so it was my first time using it) but the problem isn't really when the server closes I can't really find any pattern it's a very rare occurrence. |
|
|
| Report Abuse |
|
|
|
| 12 Oct 2015 05:10 PM |
| The problem with saving every time a value changes is that theoretically if someone spams one of the buttons that changes a value they could reach the set data change limit. |
|
|
| Report Abuse |
|
|
KingJacko
|
  |
| Joined: 20 Jun 2008 |
| Total Posts: 3944 |
|
| |
|
|
| 12 Oct 2015 05:14 PM |
| It's a very rare occurrence. I tried setting it up in a test server where it would print every time it saved a value but I couldn't recreate the problem which makes it very hard to fix. |
|
|
| Report Abuse |
|
|
|
| 12 Oct 2015 05:20 PM |
| I usually get a message from someone who's lost data about once per day. At some points there are over 150 people in my game at once so it isn't a very frequent occurrence and since the script is server side I can't ask people to report the output log. |
|
|
| Report Abuse |
|
|