AntiFiter
|
  |
| Joined: 14 May 2009 |
| Total Posts: 12290 |
|
|
| 23 Jan 2015 05:56 PM |
How would I make this script save Tables? There are a ton of values being saved, and I need to save and upload each value. Here's roughly how each slot is set up. ALL VARIABLES like 'Player' are defined, so don't worry about them.
This script is in each slot (there are around 30). They each get triggered at once so they can load up all the slot info for a player. (Yes, it's inefficient. Will upgrade later.) All I need to know is how to save the following types of values in a table, and load them (so I don't exceed the limitations of datastores.) It's also VERY slow in this way. This was my very first attempt at a datastore.
Slot: - Item - ItemType - Amount etc
-- This saves data. game.Players.PlayerRemoving:connect(function(Player) Player:WaitForDataReady() for i,v in pairs (SlotValues) do if v.ClassName == "IntValue" or v.ClassName == "StringValue" then -- So that it only saves values, not any other gui in the slot. print(v.Name) datastore:SetAsync(Slot[v].Name, Slot[v].Value) end end end) local Player = script.Parent.Parent.Parent.Parent.Parent.Parent
-- This loads up data ON JOIN. Player:WaitForDataReady() for i,v in pairs (Slot:GetChildren()) do if v.ClassName == "IntValue" or v.ClassName == "StringValue" then print(v.Name) if datastore:GetAsync(v.Name) ~= nil then v.Value = datastore:GetAsync(v.Name) else if v.ClassName == "IntValue" then v.Value = 0 elseif v.ClassName == "StringValue" then v.Value = "" end end end end
|
|
|
| Report Abuse |
|
|
chimmihc
|
  |
| Joined: 01 Sep 2014 |
| Total Posts: 17143 |
|
|
| 23 Jan 2015 06:15 PM |
| is that a free model script? cause it looks like you're trying to mix data stores with date persistence |
|
|
| Report Abuse |
|
|
AntiFiter
|
  |
| Joined: 14 May 2009 |
| Total Posts: 12290 |
|
|
| 23 Jan 2015 06:15 PM |
@Chim
It's mine
I was following a few different tutorials, so it may be mixed up. |
|
|
| Report Abuse |
|
|
chimmihc
|
  |
| Joined: 01 Sep 2014 |
| Total Posts: 17143 |
|
|
| 23 Jan 2015 06:17 PM |
Player:WaitForDataReady()
and
Player:WaitForDataReady()
are for data persistence, data stores dont save data to the player |
|
|
| Report Abuse |
|
|
AntiFiter
|
  |
| Joined: 14 May 2009 |
| Total Posts: 12290 |
|
|
| 23 Jan 2015 06:24 PM |
| Minus that, how would I save tables |
|
|
| Report Abuse |
|
|
AntiFiter
|
  |
| Joined: 14 May 2009 |
| Total Posts: 12290 |
|
|
| 23 Jan 2015 07:22 PM |
Just how do I save tables? And then SetAsync in a way like :SetAsync({
Value1 = script.Parent.Value1Assignment.Value Value2 = script.Parent.Value2Assignment.Value etc
})
The point is, I need a quick way to do it, and a way that does not exceed the request limit. |
|
|
| Report Abuse |
|
|
|
| 23 Jan 2015 07:28 PM |
I had the same question, I had the idea though to use a for loop and yeh:
local table = {thing = 1, thing2 = 10}
for i, v in pairs(table) do a = Instance.new("NumberValue") a.Name = table[i] a.Value = datastorepath:GetAsync(key) end
Something along those lines. |
|
|
| Report Abuse |
|
|
AntiFiter
|
  |
| Joined: 14 May 2009 |
| Total Posts: 12290 |
|
|
| 23 Jan 2015 07:29 PM |
I don't have a key in my script. Do I need one?
Also, your seems like it just does the same thing as mine. saves each value one by one |
|
|
| Report Abuse |
|
|
|
| 23 Jan 2015 07:34 PM |
In order to fetch the data, yes.:
local table = {thing, thing2}
for i = 1,#table do a = Instance.new("NumberValue") a.Name = table[i] a.Value = datastorepath:GetAsync(table[i]) end |
|
|
| Report Abuse |
|
|
AntiFiter
|
  |
| Joined: 14 May 2009 |
| Total Posts: 12290 |
|
|
| 23 Jan 2015 07:35 PM |
Yea, that's not ideal for my game, so I have to use a table. Somehow.
But apparently no one who has used DataStores for a while is online today :( |
|
|
| Report Abuse |
|
|
|
| 23 Jan 2015 07:42 PM |
To save a table, simply use ::setAsync() on the table. It automatically converts the table to JSON, so you'll be all good. However, all the stored values within the table must be of one class.
::_::goto_ |
|
|
| Report Abuse |
|
|
AntiFiter
|
  |
| Joined: 14 May 2009 |
| Total Posts: 12290 |
|
|
| 23 Jan 2015 07:45 PM |
| I don't know what JSON means, or what you mean by class. can you elaborate |
|
|
| Report Abuse |
|
|
|
| 23 Jan 2015 08:04 PM |
I think it's a type of format for saving data, here are some functions:
EncodeJSON() DecodeJSON() |
|
|
| Report Abuse |
|
|
|
| 23 Jan 2015 08:10 PM |
JSON (JavaScript Object Notation) is essentially a string, with a table's compressed data. It looks like this,
['first','second','etc']
That is a standard numeric table. However, JSON is also compatible with key-value pairs, such as:
[ 'firstkey' : 'first', 'secondkey' : 'second' ]
All tables, when stored in DataStore, are compressed to JSON, which is a string. This also means, that when you attempt to retrieve the data, any ROBLOX-based classes (Vector3, CFrame, Color3, etc.), will be set as nil during the compression.
You may store string / numbers / booleans / et. all. within JSON though.
::_::goto_ |
|
|
| Report Abuse |
|
|
AntiFiter
|
  |
| Joined: 14 May 2009 |
| Total Posts: 12290 |
|
|
| 23 Jan 2015 08:19 PM |
| Regardless, how would I go about saving a table and SetAsync like I showed above? I need an example |
|
|
| Report Abuse |
|
|
AntiFiter
|
  |
| Joined: 14 May 2009 |
| Total Posts: 12290 |
|
|
| 23 Jan 2015 08:43 PM |
Do I just need to do:
Data:SetAsync(value1 = script.Parent.Value, value2 = script.Parent.Value2.Value) |
|
|
| Report Abuse |
|
|
AntiFiter
|
  |
| Joined: 14 May 2009 |
| Total Posts: 12290 |
|
|
| 23 Jan 2015 10:24 PM |
| Is there a way to use just 1 SetAsync (or GetAsync) to load all/most data? |
|
|
| Report Abuse |
|
|