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: Help With Data Stores

Previous Thread :: Next Thread 
David83335 is not online. David83335
Joined: 25 Aug 2009
Total Posts: 49
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 is not online. 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 is not online. 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 is not online. 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
David83335 is not online. David83335
Joined: 25 Aug 2009
Total Posts: 49
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
David83335 is not online. David83335
Joined: 25 Aug 2009
Total Posts: 49
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 is not online. KingJacko
Joined: 20 Jun 2008
Total Posts: 3944
12 Oct 2015 05:11 PM
is there any output?
Report Abuse
David83335 is not online. David83335
Joined: 25 Aug 2009
Total Posts: 49
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
David83335 is not online. David83335
Joined: 25 Aug 2009
Total Posts: 49
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
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