Answered by
8 years ago Edited 8 years ago
You can only have one (1) type of statistic stored in a table in a datastore...
plr.SaveFolder
cannot be saved, because it is not the same type of object
as plr.SaveFolder.SaveStone.Value
Solution?
JSONEncoding, and JSONDecoding...
To do JSONEncoding:
http://wiki.roblox.com/index.php?title=API:Class/HttpService/JSONEncode
Why is this useful? You can convert data into Strings.
But how do I do this?
First, you must access the HttpService, this does not mean HttpService needs to be enabled though:
1 | HttpService = game:GetService( "HttpService" ) |
Now, you will give the table you want to encode:
1 | local atable = { "A" , "B" , "a" , "b" } |
Since you have this, you can now begin to encode it...
1 | local encoding = HttpService:JSONEncode(atable) |
Now, you have a string.
http://wiki.roblox.com/index.php?title=API:Class/HttpService/JSONDecode
When retrieving the data given to the datastore, you must now decode the encoding...
You can go about this by using the JSONDecode("AString")
event...
1 | local decoding = HttpService:JSONDecode(encoding) |
Now you have a table... hooray.
As for your script, now that I have explained this... will go as follows:
01 | HttpService = game:GetService( "HttpService" ) |
03 | local EncodedTable = DSService:GetAsync(uniquekey) |
06 | DecodedTable = EncodedTable:JSONDecode(EncodedTable) |
08 | if DecodedTable ~ = nil then |
09 | savevalue.Value = DecodedTable [ 1 ] |
10 | SaveFolder = DecodedTable [ 2 ] |
11 | SaveStone.Value = DecodedTable [ 3 ] |
12 | SaveClay.Value = DecodedTable [ 4 ] |
13 | SaveBrick.Value = DecodedTable [ 5 ] |
14 | SaveRawIron.Value = DecodedTable [ 6 ] |
15 | SaveIron.Value = DecodedTable [ 7 ] |
16 | plr.PlayerGui.Invintory.Inv.Stone.Text = "Stone: " ..SaveStone.Value |
17 | plr.PlayerGui.Invintory.Inv.Clay.Text = "Stone: " ..SaveClay.Value |
18 | plr.PlayerGui.Invintory.Inv.Bricks.Text = "Stone: " ..SaveBrick.Value |
19 | plr.PlayerGui.Invintory.Inv.RawIron.Text = "Stone: " ..SaveRawIron.Value |
20 | plr.PlayerGui.Invintory.Inv.Iron.Text = "Stone: " ..SaveIron.Value |
22 | local NumbersForSaving = { |
30 | local EnocdedNFS = HttpService:JSONEncode(NumbersForSaving) |
31 | DSService:SetAsync(uniquekey,EncodedNFS) |
That's for the PlayerAdded, for the PlayerRemoving:
01 | game.Players.PlayerRemoving:connect( function (plr) |
02 | local uniquekey = 'id-' ..plr.userId |
03 | local Savetable = { plr.leaderstats.Cash.Value, |
05 | plr.SaveFolder.SaveStone.Value, |
06 | plr.SaveFolder.SaveClay.Value, |
07 | plr.SaveFolder.SaveBrick.Value, |
08 | plr.SaveFolder.SaveRawIron.Value, |
09 | plr.SaveFolder.SaveIron.Value } |
10 | local EncodedSt = HttpService:JSONEncode(Savetable) |
11 | DSService:SetAsync(uniquekey, EncodedSt) |
This should do it for you... There could be errors, it was done in the Tab for this.
-Taryo
Thgirypoc (C) 6102 Oyrat