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: Data Persistance Trouble

Previous Thread :: Next Thread 
DiscoTrio is not online. DiscoTrio
Joined: 08 Aug 2008
Total Posts: 441
31 Dec 2012 01:20 PM
Hello,

I am having a bit of an issue trying to load a string with the LoadString() method. This pcall function always returns the following:

Error: Argument 1 missing or nil.

Here is my script:

local ok, ret = pcall(function() return player:LoadString(items) end)
if ok then
local item_t = RbxUtility.DecodeJSON(ret)
if #items_t > 0 then
console("Loading " .. #item_t .. "items...")
for i=1,#item_t do
console("Loaded item: " .. item_t[i] .. ", ")
game.Workspace.Items:findFirstChild(item_t[i]):Clone().Parent = player.Items
end
console("Done loading items. ")
else console("Nothing to load. ") end
else console("Error: " .. ret .. ". ") end

As you an see, the stuff in the middle (includint he decodejson thing) is not relevant to this error because PCall captures an error with this bit: local ok, ret = pcall(function() return player:LoadString(items) end)

Any ideas?
Report Abuse
doombringer42 is not online. doombringer42
Joined: 13 Nov 2007
Total Posts: 5445
31 Dec 2012 01:25 PM
line?

¬ LuaLearners Elite/Writer
Report Abuse
DrHaximus is not online. DrHaximus
Joined: 22 Nov 2011
Total Posts: 8410
31 Dec 2012 01:25 PM
Does the output specify which function is without an argument?
Report Abuse
DiscoTrio is not online. DiscoTrio
Joined: 08 Aug 2008
Total Posts: 441
31 Dec 2012 01:28 PM
It does not, because I am using pcall. Due to data persistence not working in solo or local server mode the console() function I made posts errors and such to the screen on the online server.

This means that we know that the error is coming from the pcall function... the only place it can be posted from.

So it appears to me that it has a problem with LoadString()
Report Abuse
DiscoTrio is not online. DiscoTrio
Joined: 08 Aug 2008
Total Posts: 441
31 Dec 2012 01:29 PM
This being the full function the error is coming from:

(function() return player:LoadString(items) end)

I know that the key "items" is valid as well as player.
Report Abuse
doombringer42 is not online. doombringer42
Joined: 13 Nov 2007
Total Posts: 5445
31 Dec 2012 01:31 PM
in that case item must be nil. post the rest of your script and i'll look at it.

¬ LuaLearners Elite/Writer
Report Abuse
YellowBrick1 is not online. YellowBrick1
Joined: 06 May 2009
Total Posts: 865
31 Dec 2012 01:31 PM
clearly, items = nil. Show us the rest of the script?
Report Abuse
DiscoTrio is not online. DiscoTrio
Joined: 08 Aug 2008
Total Posts: 441
31 Dec 2012 01:32 PM
Okay, I apologize for any formatting that the forum removes from the script:


game.Players.PlayerAdded:connect(function(player)
local RbxUtility = LoadLibrary("RbxUtility")
console_box = player.PlayerGui.MainMenu.main.console

function console(new)
console_box.Text = (console_box.Text .. " " .. new)
end

wait()
console("Begin waiting for data to be ready...")
player:WaitForDataReady()
console("Data ready! Placing main groups...")

local questGroup = Instance.new("StringValue", player)
questGroup.Name = "Quests"

local itemGroup = Instance.new("StringValue", player)
itemGroup.Name = "Items"

local money = Instance.new("NumberValue", player)
money.Name = "Money"
money.Value = 100

local messages = Instance.new("StringValue", player)
messages.Name = "Messages"

game.Lighting.Levels:Clone().Parent = player

console("All main groups placed!")

local ok, ret = pcall(function() return player:LoadString(items) end)
if ok then
local item_t = RbxUtility.DecodeJSON(ret)
if #items_t > 0 then
console("Loading " .. #item_t .. "items...")
for i=1,#item_t do
console("Loaded item: " .. item_t[i] .. ", ")
game.Workspace.Items:findFirstChild(item_t[i]):Clone().Parent = player.Items
end
console("Done loading items. ")
else console("Nothing to load. ") end
else console("Error: " .. ret .. ". ") end
end)


game.Players.PlayerRemoving:connect(function(player)
player:WaitForDataReady()

local items = {}
local item_t = player.Items:GetChildren()
for i=1,#item_t do
items[i] = item_t[i].Name
end
local succ, ret = pcall(function() player:SaveString('items', RbxUtility.EncodeJSON(items)) end)
if succ then print("saved.")
else print("Saving error", ret) end
end)
Report Abuse
DiscoTrio is not online. DiscoTrio
Joined: 08 Aug 2008
Total Posts: 441
31 Dec 2012 01:33 PM
Here is a copy in pastebin:

pastebin.com/9eX4BavP
Report Abuse
YellowBrick1 is not online. YellowBrick1
Joined: 06 May 2009
Total Posts: 865
31 Dec 2012 01:34 PM
I honestly don't see 'items' defined anywhere.
Report Abuse
doombringer42 is not online. doombringer42
Joined: 13 Nov 2007
Total Posts: 5445
31 Dec 2012 01:35 PM
put quotes around 'items'.

¬ LuaLearners Elite/Writer
Report Abuse
DiscoTrio is not online. DiscoTrio
Joined: 08 Aug 2008
Total Posts: 441
31 Dec 2012 01:35 PM
(function() player:SaveString('items', RbxUtility.EncodeJSON(items)) end)

This happens at the bottom of the script when a player disconnects.
Report Abuse
DiscoTrio is not online. DiscoTrio
Joined: 08 Aug 2008
Total Posts: 441
31 Dec 2012 01:43 PM
with quotes of the " and ' variety the script does not seem to execute past the pcall function or return errors.
Report Abuse
doombringer42 is not online. doombringer42
Joined: 13 Nov 2007
Total Posts: 5445
31 Dec 2012 01:45 PM
local item_t = RbxUtility.DecodeJSON(ret)
if #items_t > 0 then

you got a typo. change item_t to items_t.

¬ LuaLearners Elite/Writer
Report Abuse
DiscoTrio is not online. DiscoTrio
Joined: 08 Aug 2008
Total Posts: 441
31 Dec 2012 01:50 PM
That was the error I spent the past day and a half on?

Thnaks a ton! Im in your debt :P
Report Abuse
doombringer42 is not online. doombringer42
Joined: 13 Nov 2007
Total Posts: 5445
31 Dec 2012 01:51 PM
i'm not sure if that will ultimately solve your problem... test it first

¬ LuaLearners Elite/Writer
Report Abuse
DiscoTrio is not online. DiscoTrio
Joined: 08 Aug 2008
Total Posts: 441
31 Dec 2012 01:54 PM
I have 3 monitors, a fast computer, and a can of Red Bull. I have tested this a dozen times since you pointed out the error.

:3
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