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 » Scripting Helpers
Home Search
 

Re: Old Data Persistence Deletion of Keys?

Previous Thread :: Next Thread 
superswordfish is not online. superswordfish
Joined: 14 Jun 2013
Total Posts: 1336
01 Jun 2014 02:13 PM
With the old Data Persistence system, do I have to worry about deleting keys? Like, if they reset thier score to 0, is it ok if the data becomes saved at 0, instead of blank data?

Also, how would I set up a Player leaving/rejoining saving system with the new DataStores? I want to use the DataStores since the old Data Persistence is not recommended for this, but idk how to use the DataStores this way. Can you help? Thanks!
Report Abuse
superswordfish is not online. superswordfish
Joined: 14 Jun 2013
Total Posts: 1336
02 Jun 2014 09:48 AM
Bump
Report Abuse
Ultraw is not online. Ultraw
Joined: 20 Nov 2010
Total Posts: 6575
02 Jun 2014 09:55 AM
I did this for a basic "score" value in leaderstats. I dont know how you want to do it.

datastoreName = "Score"

ds = game:GetService("DataStoreService"):GetDataStore(datastoreName)

game.Players.PlayerEntered:connect(function(p)
if ds:GetAsync("user_"..p.Name) then
p.leaderstats.Score.Value = ds:GetAsync("user_"..p.Name)
end end

game.Players.PlayerRemoving:connect(function(p)
ds:SetAsync("user_"..p.Name,p.leaderstats.Score.Value
end
Report Abuse
Ultraw is not online. Ultraw
Joined: 20 Nov 2010
Total Posts: 6575
02 Jun 2014 09:55 AM
Sorry..

datastoreName = "Score"

ds = game:GetService("DataStoreService"):GetDataStore(datastoreName)

game.Players.PlayerEntered:connect(function(p)
if ds:GetAsync("user_"..p.Name) then
p.leaderstats.Score.Value = ds:GetAsync("user_"..p.Name)
end end)

game.Players.PlayerRemoving:connect(function(p)
ds:SetAsync("user_"..p.Name,p.leaderstats.Score.Value
end)
Report Abuse
superswordfish is not online. superswordfish
Joined: 14 Jun 2013
Total Posts: 1336
02 Jun 2014 10:10 AM
I see. The issue I have is I want to save several values, not just 1, like Score, Money, and Level. Is there a way to do this?
Report Abuse
Ultraw is not online. Ultraw
Joined: 20 Nov 2010
Total Posts: 6575
02 Jun 2014 10:16 AM

level = game:GetService("DataStoreService"):GetDataStore("Level")
money = game:GetService("DataStoreService"):GetDataStore("Money")
score = game:GetService("DataStoreService"):GetDataStore("Score")

game.Players.PlayerEntered:connect(function(p)
if level:GetAsync("user_"..p.Name) then
p.leaderstats.Level.Value = level:GetAsync("user_"..p.Name)
end
if money:GetAsync("user_"..p.Name) then
p.leaderstats.Money.Value = money:GetAsync("user_"..p.Name)
end
if score:GetAsync("user_"..p.Name) then
p.leaderstats.Score.Value = score:GetAsync("user_"..p.Name)
end
end)

end)

game.Players.PlayerRemoving:connect(function(p)
level:SetAsync("user_"..p.Name,p.leaderstats.Level.Value)
money:SetAsync("user_"..p.Name,p.leaderstats.Money.Value)
score:SetAsync("user_"..p.Name,p.leaderstats.Score.Value)
end)
Report Abuse
superswordfish is not online. superswordfish
Joined: 14 Jun 2013
Total Posts: 1336
02 Jun 2014 10:26 AM
Wouldn't that make the Level, Score, and Money all save and load as the same value though, or am I missing something?
Report Abuse
Ultraw is not online. Ultraw
Joined: 20 Nov 2010
Total Posts: 6575
02 Jun 2014 10:26 AM
No, they are all different DataStores.

Report Abuse
islandmaker2012 is not online. islandmaker2012
Joined: 07 Nov 2012
Total Posts: 9327
02 Jun 2014 10:27 AM
p.leaderstats.Score.Value = score:GetAsync("user_"..p.Name)


No

It gwts a global datastore, and sets a specificly named key to a value
Report Abuse
AgentFirefox is not online. AgentFirefox
Top 100 Poster
Joined: 20 Jun 2008
Total Posts: 22404
02 Jun 2014 10:41 AM
I recommend staying away from player leaving save system by itself. You should also save data periodically while the server is running. If you do use player leave to save data, also make sure that you do not overwrite their save data if they leave as soon as they join (for example, if a player disconnects while loading, and all their stat values have been created, but the stats were not loaded from the data store yet, the default values (typically 0) will be saved OVER their actual previous values).
Report Abuse
superswordfish is not online. superswordfish
Joined: 14 Jun 2013
Total Posts: 1336
02 Jun 2014 10:46 AM
Ohhhh, so basically, you have 3 DataStores for each value, and then save the Player's name in each one to keep track of how much they have for each value. Cool :D.
Report Abuse
superswordfish is not online. superswordfish
Joined: 14 Jun 2013
Total Posts: 1336
02 Jun 2014 10:50 AM
Ok. How would I make sure that the data doesn't overwrite if the player leaves before the game loads?
Report Abuse
AgentFirefox is not online. AgentFirefox
Top 100 Poster
Joined: 20 Jun 2008
Total Posts: 22404
02 Jun 2014 10:53 AM
I also recommend using one data store (named 'Stats' or something) and save a table instead of wasting your time with three data stores. Also, save by userId, not player Name (players can change their names now).



local stats = game:GetService("DataStoreService"):GetDataStore("Stats")

game.Players.PlayerEntered:connect(function(p)
local pstats = stats:GetAsync("user_"..p.userId)
if pstats then
p.leaderstats.Level.Value = pstats.Level
p.leaderstats.Money.Value = pstats.Money
p.leaderstats.Score.Value = pstats.Score
end
end)

end)

game.Players.PlayerRemoving:connect(function(p)
stats:SetAsync("user_"..p.userId, {
Level = p.leaderstats.Level.Value,
Money = p.leaderstats.Money.Value,
Score = p.leaderstats.Score.Value
})
end)



Though I do highly recommend using UpdateAsync instead of SetAsync, and remember my old post about making sure default data isn't overwritten.
Report Abuse
superswordfish is not online. superswordfish
Joined: 14 Jun 2013
Total Posts: 1336
02 Jun 2014 11:01 AM
Ok thanks. How do I make sure that the default data isn't overwritten?
Report Abuse
superswordfish is not online. superswordfish
Joined: 14 Jun 2013
Total Posts: 1336
02 Jun 2014 02:18 PM
Bump :P.
Report Abuse
superswordfish is not online. superswordfish
Joined: 14 Jun 2013
Total Posts: 1336
02 Jun 2014 05:40 PM
Bump again.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • 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