|
| 05 Aug 2014 11:11 AM |
I used to know how to use data persistence fairly well, but now I can't remember at all. In my game, the player gets empty stringvalues inserted in their player just so other scripts can see whether a player has done a certain thing or has bought a certain item. Does it even make a difference that they have no text? Here's just a small sample that didn't work. Just so you know, the table contains all the values that your player can contain:
swords = {"Armor", "Darkheart", "Firebrand", "Ghostwalker", "IceDagger", "Illumina", "Medkit", "Venomshank", "Windforce"}
game.Players.PlayerAdded:connect(function(player) player:WaitForDataReady() for _, v in pairs(swords) do player:LoadString(v) end)
game.Players.PlayerRemoving:connect(function(player) for _, v in pairs(player:GetChildren()) do --because their player now contains some of the string values if v.ClassName == "StringValue" then if v.Value == "" then v:SaveString(v, "") end end end end)
Outfoxing Foxes |
|
|
| Report Abuse |
|
|
|
| 05 Aug 2014 11:12 AM |
Whoopsies, forgot an end
game.Players.PlayerAdded:connect(function(player) player:WaitForDataReady() for _, v in pairs(swords) do player:LoadString(v) end end)
game.Players.PlayerRemoving:connect(function(player) for _, v in pairs(player:GetChildren()) do --because their player now contains some of the string values if v.ClassName == "StringValue" then if v.Value == "" then v:SaveString(v, "") end end end end)
Outfoxing Foxes |
|
|
| Report Abuse |
|
|
| |
|
blockoo
|
  |
| Joined: 08 Nov 2007 |
| Total Posts: 17202 |
|
|
| 05 Aug 2014 11:35 AM |
| Why are you using DataPersistence instead of DataStore? |
|
|
| Report Abuse |
|
|
|
| 05 Aug 2014 11:51 AM |
All right, how do you use datastore to save empty string values?
Outfoxing Foxes |
|
|
| Report Abuse |
|
|
blockoo
|
  |
| Joined: 08 Nov 2007 |
| Total Posts: 17202 |
|
|
| 05 Aug 2014 11:54 AM |
| Well, first off have you ever used/studied DataStore before? |
|
|
| Report Abuse |
|
|
|
| 05 Aug 2014 11:55 AM |
I'm looking at it on the wiki right now.
Outfoxing Foxes |
|
|
| Report Abuse |
|
|
blockoo
|
  |
| Joined: 08 Nov 2007 |
| Total Posts: 17202 |
|
|
| 05 Aug 2014 12:07 PM |
Ok, so since a DataStore is like a table where you can name the indices, I suggest naming the index as the userId of the player. That way when you try and load it you can just use the player's userId to recover the data. Here's an example: strings = game:GetService("DataStoreService"):GetDataStore("Strings") strings:SetAsync(tostring(player.userId), "YOUR STRING")
Then, when you load it later: strings:GetAsync(tostring(player.userId))
And that will return the string that you saved, even if it's blank. |
|
|
| Report Abuse |
|
|
|
| 05 Aug 2014 12:24 PM |
Thanks. How could you save multiple strings?
Outfoxing Foxes |
|
|
| Report Abuse |
|
|
|
| 05 Aug 2014 12:33 PM |
Strange...
I created a GUI with a save and a load button, and put this script inside the frame containing the save and load buttons:
player = script.Parent.Parent.Parent.Parent datastore = game:GetService("DataStoreService"):GetDataStore("strings")
script.Parent.Load.MouseButton1Down:connect(function() player:WaitForDataReady() datastore:GetAsync(tostring(player.userId)) end)
script.Parent.Save.MouseButton1Down:connect(function() for _, v in pairs(player:GetChildren()) do if v.ClassName == "StringValue" then if v.Value == "" then if v.Name ~= "Sword" then print(v.Name) datastore:SetAsync(tostring(player.userId), v) end end end end end)
Output: Data contains object that cannot be stored (line 16)
The object it's saving is just an ordinary StringValue. Why doesn't it save it?
Outfoxing Foxes |
|
|
| Report Abuse |
|
|
|
| 05 Aug 2014 01:07 PM |
Fixed it. Took me a few minutes, but I managed o3o
Outfoxing Foxes |
|
|
| Report Abuse |
|
|
blockoo
|
  |
| Joined: 08 Nov 2007 |
| Total Posts: 17202 |
|
|
| 05 Aug 2014 01:46 PM |
| Oh btw, with DataStore you don't need to use WaitForDataReady() since the save system isn't player-based |
|
|
| Report Abuse |
|
|