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
 

Saving and Loading JSON.

Previous Thread :: Next Thread 
luckysun3 is not online. luckysun3
Joined: 23 Oct 2013
Total Posts: 37
08 Oct 2013 02:14 AM
There seems to be a major problem with this, I've been fiddling with the code all night and can't seem to figure out what's wrong, I don't typically use Tables. And, since it has to do with Data, I can't run it in solo.

I'm 99% certain, it has to do with how I've done my tables, or the loading on line 61 and down. .-. Any thoughts?

game.Players.PlayerRemoving:connect(function(plr)
plr:WaitForDataReady()
local rbxUtl = assert(LoadLibrary("RbxUtility"))
thedata = {
["level"] = tostring(game.ServerStorage:FindFirstChild(plr.Name).Stats2.Level.Value),
["start"] = tostring(game.ServerStorage:FindFirstChild(plr.Name).Stats2.Start.Value),
["first"] = tostring(game.ServerStorage:FindFirstChild(plr.Name).Stats2.First.Value),
["bless"] = tostring(game.ServerStorage:FindFirstChild(plr.Name).Stats2.Blessed.Value),
["xp"] = tostring(game.ServerStorage:FindFirstChild(plr.Name).Stats2.Xp.Value),
["egg"] = game.ServerStorage:FindFirstChild(plr.Name).Stats2.EggPass.Value,
["quest1"] = tostring(game.ServerStorage:FindFirstChild(plr.Name).Stats2.Quest1.Value),
["quest2"] = tostring(game.ServerStorage:FindFirstChild(plr.Name).Stats2.Quest2.Value),
["quest3"] = tostring(game.ServerStorage:FindFirstChild(plr.Name).Stats2.Quest3.Value),
["prestige"] = tostring(game.ServerStorage:FindFirstChild(plr.Name).Stats2.Prestige.Value),
["event"] = game.ServerStorage:FindFirstChild(plr.Name).Stats2.Event.Value
}
if pcall(function() plr:SaveString("data", rbxUtl:EncodeJSON(thedata)) end) then
print("Saved.")
else
print("Failed to Save")
end
end)

game.Players.PlayerAdded:connect(function(plr)
plr:WaitForDataReady()
if game.ServerStorage:FindFirstChild(plr.Name)~=nil then
game.ServerStorage:FindFirstChild(plr.Name):Destroy()
end
local con = Instance.new("IntValue")
con.Parent = game.ServerStorage
con.Name = plr.Name
local l = Instance.new("IntValue")
l.Parent = con
l.Name = "Stats2"
local level = Instance.new("IntValue",l)
level.Name = "Level"
local start = Instance.new("IntValue",l)
start.Name = "Start"
local First = Instance.new("BoolValue",l)
First.Name = "First"
local Bless = Instance.new("BoolValue",l)
Bless.Name = "Blessed"
local Xp = Instance.new("IntValue",l)
Xp.Name = "Xp"
local EggPass = Instance.new("StringValue",l)
EggPass.Name = "EggPass"
local Quest1 = Instance.new("IntValue",l)
Quest1.Name = "Quest1"
local Quest2 = Instance.new("IntValue",l)
Quest2.Name = "Quest2"
local Quest3 = Instance.new("IntValue",l)
Quest3.Name = "Quest3"
local Prestige = Instance.new("IntValue",l)
Prestige.Name = "Prestige"
local Event = Instance.new("StringValue",l)
Event.Name = "Event"
local rbxUtl = assert(LoadLibrary("RbxUtility"))
local data
if pcall(function() data = plr:LoadString("data") end) then print("Loaded") else print("Failed to Load") end
data = rbxUtl:DecodeJSON(data)
game.ServerStorage:FindFirstChild(plr.Name).Stats2.Level.Value = tonumber(data["level"])
game.ServerStorage:FindFirstChild(plr.Name).Stats2.Start.Value = tonumber(data["start"])
game.ServerStorage:FindFirstChild(plr.Name).Stats2.First.Value = data["first"]
game.ServerStorage:FindFirstChild(plr.Name).Stats2.Blessed.Value = data["bless"]
game.ServerStorage:FindFirstChild(plr.Name).Stats2.Xp.Value = tonumber(data["xp"])
game.ServerStorage:FindFirstChild(plr.Name).Stats2.EggPass.Value = data["egg"]
game.ServerStorage:FindFirstChild(plr.Name).Stats2.Quest1.Value = tonumber(data["quest1"])
game.ServerStorage:FindFirstChild(plr.Name).Stats2.Quest2.Value = tonumber(data["quest2"])
game.ServerStorage:FindFirstChild(plr.Name).Stats2.Quest3.Value = tonumber(data["quest3"])
game.ServerStorage:FindFirstChild(plr.Name).Stats2.Prestige.Value = tonumber(data["prestige"])
game.ServerStorage:FindFirstChild(plr.Name).Stats2.Event.Value = data["event"]

end)
Report Abuse
luckysun3 is not online. luckysun3
Joined: 23 Oct 2013
Total Posts: 37
08 Oct 2013 02:17 AM
Basically, the data can change. When I leave, and enter a server, it resets back to the default values.
Say I got level 10, then left (It should save), then went to a server, it claims I'm still level 0.
Report Abuse
9HB is not online. 9HB
Joined: 11 Dec 2012
Total Posts: 2461
08 Oct 2013 02:52 AM
Instead of posting 9001 lines of code maybe you can ppst from line 61 to where you think error stops?

Also your lines aren't numbered, I don't want to go through numbering them all myself.
Report Abuse
luckysun3 is not online. luckysun3
Joined: 23 Oct 2013
Total Posts: 37
08 Oct 2013 03:05 AM
Considering there is only 73 lines of code, and one could have them automatically numbered via notepad, I didn't see the issue.
But, since you brought it up, I'll attempt to number it. (It'd be nice if roblox had a [code/] [/code] type system to add spoilers and number the lines)

Possible issue number one:
Line 17; if pcall(function() plr:SaveString("data", rbxUtl:EncodeJSON(thedata)) end) then
Line 18; print("Saved.")
Line 19; else
Line 20; print("Failed to Save")
Line 21; end
Line 22; end)
Suspected issue: Possibly not the proper table format in the code?
Example of the table:
thedata = {
["level"] = tostring(game.ServerStorage:FindFirstChild(plr.Name).Stats2.Level.Value),
}

Possible issue number two:
Line 57; local rbxUtl = assert(LoadLibrary("RbxUtility"))
Line 58; local data
Line 59; if pcall(function() data = plr:LoadString("data") end) then print("Loaded") else print("Failed to Load")
Line 60; end
Line 61; data = rbxUtl:DecodeJSON(data)
Line 62; game.ServerStorage:FindFirstChild(plr.Name).Stats2.Level.Value = tonumber(data["level"])
Suspected issue: Loaded it in an incorrect way, calling the wrong value?
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