|
| 01 Jun 2014 10:16 PM |
If I create some stats ...
local DS = game:GetService("DataStoreService"):GetOrderedDataStore("Wins") local u = assert(LoadLibrary("RbxUtility")) stats = {Tix = 0, Wins Tokens = 0, Wins = 0}
function PlayerAdded(p)
local strstats = u.EncodeJSON(stats) local ls = Instance.new("IntValue", p) ls.Name = "leaderstats" -- what do I do to save those stats as IntValues under leaderstats? strstats.Wins.Changed:connect(function(v) DS:SetAsync(p.userId, v) end) end
-- connection line stuff
|
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 01 Jun 2014 10:17 PM |
for key, value in next, stats do local stat = Instance.new("IntValue", ls); stat.Name = key; stat.Value = value; end |
|
|
| Report Abuse |
|
|
|
| 01 Jun 2014 10:20 PM |
| Should I rid the JSON part? I just wanted to make a faster stat creation. |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 01 Jun 2014 10:21 PM |
| If you plan on saving this, you should convert it to a JSON when you save and back to a table after you load. |
|
|
| Report Abuse |
|
|
wazap
|
  |
| Joined: 29 Jun 2007 |
| Total Posts: 23234 |
|
|
| 01 Jun 2014 10:26 PM |
You can save tables to DataStore directly without converting
"Dont judge a user by what they're wearing"
|
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 01 Jun 2014 10:28 PM |
| Is it not less "space-consuming" if you store it as a string in JSON format? |
|
|
| Report Abuse |
|
|
wazap
|
  |
| Joined: 29 Jun 2007 |
| Total Posts: 23234 |
|
|
| 01 Jun 2014 10:33 PM |
| It automatically converts to JSON anyways so idk. Its easier to code without converting tbh. |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 01 Jun 2014 10:35 PM |
| Oh, it is? And when you load it, the value returned is automatically a table I'll assume? I don't know too much about datastore since I never actually need to save anything |
|
|
| Report Abuse |
|
|
wazap
|
  |
| Joined: 29 Jun 2007 |
| Total Posts: 23234 |
|
|
| 01 Jun 2014 10:36 PM |
Yup, its converted automatically
"Dont judge a user by what they're wearing"
|
|
|
| Report Abuse |
|
|