generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: How to save empty string values?

Previous Thread :: Next Thread 
idyllically is not online. idyllically
Joined: 13 Mar 2010
Total Posts: 4622
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
idyllically is not online. idyllically
Joined: 13 Mar 2010
Total Posts: 4622
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
idyllically is not online. idyllically
Joined: 13 Mar 2010
Total Posts: 4622
05 Aug 2014 11:26 AM
Bump

Outfoxing Foxes
Report Abuse
blockoo is not online. blockoo
Joined: 08 Nov 2007
Total Posts: 17202
05 Aug 2014 11:35 AM
Why are you using DataPersistence instead of DataStore?
Report Abuse
idyllically is not online. idyllically
Joined: 13 Mar 2010
Total Posts: 4622
05 Aug 2014 11:51 AM
All right, how do you use datastore to save empty string values?

Outfoxing Foxes
Report Abuse
blockoo is not online. 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
idyllically is not online. idyllically
Joined: 13 Mar 2010
Total Posts: 4622
05 Aug 2014 11:55 AM
I'm looking at it on the wiki right now.

Outfoxing Foxes
Report Abuse
blockoo is not online. 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
idyllically is not online. idyllically
Joined: 13 Mar 2010
Total Posts: 4622
05 Aug 2014 12:24 PM
Thanks. How could you save multiple strings?

Outfoxing Foxes
Report Abuse
idyllically is not online. idyllically
Joined: 13 Mar 2010
Total Posts: 4622
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
idyllically is not online. idyllically
Joined: 13 Mar 2010
Total Posts: 4622
05 Aug 2014 01:07 PM
Fixed it. Took me a few minutes, but I managed o3o

Outfoxing Foxes
Report Abuse
blockoo is not online. 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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image