|
| 29 Sep 2015 09:52 PM |
Helping script a game, what is the best way to do DataStores? I noticed that if I just UpdateSync with a Changed event connected to my NumberValue, it only saves sometimes.
Post your favorite methods and suggestions. |
|
|
| Report Abuse |
|
|
Blues714
|
  |
| Joined: 23 Dec 2008 |
| Total Posts: 6507 |
|
|
| 29 Sep 2015 09:58 PM |
my way;
game.Players.PlayerAdded:connect(function(Player) game.ReplicatedStorage.Framework.PlayerData:Clone().Parent = Player local DataStoreService = game:GetService("DataStoreService") [datastore] = DataStoreService:GetDataStore("[name of datastore]")
Key = "user_"..Player.userId -- saves by player's id wait() [data] = Player.PlayerData[name of data] [data].Value = [datastore]:GetAsync(Key) or 1
[data].Changed:connect(function(Val) [datastore]:SetAsync(Key, [data].Value) end) print("Data ready for"..Key) end) |
|
|
| Report Abuse |
|
|
|
| 29 Sep 2015 10:00 PM |
| oh god that is a terrible way |
|
|
| Report Abuse |
|
|
Blues714
|
  |
| Joined: 23 Dec 2008 |
| Total Posts: 6507 |
|
|
| 29 Sep 2015 10:00 PM |
| i didn't want ur opinion qq |
|
|
| Report Abuse |
|
|
|
| 29 Sep 2015 10:00 PM |
| SetAsync will always make sure to save the value? |
|
|
| Report Abuse |
|
|
Blues714
|
  |
| Joined: 23 Dec 2008 |
| Total Posts: 6507 |
|
|
| 29 Sep 2015 10:02 PM |
| it sets a value or overwrites the old value |
|
|
| Report Abuse |
|
|
|
| 29 Sep 2015 10:13 PM |
| Okay, since people (a person) claims that's horrible, anyone else want to share? |
|
|
| Report Abuse |
|
|
frriend
|
  |
| Joined: 07 Feb 2010 |
| Total Posts: 577 |
|
|
| 29 Sep 2015 10:14 PM |
SetAsync = Sets the value GetAsync = Gets the value |
|
|
| Report Abuse |
|
|
Blues714
|
  |
| Joined: 23 Dec 2008 |
| Total Posts: 6507 |
|
| |
|