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 persistent error.

Previous Thread :: Next Thread 
Adam2090 is not online. Adam2090
Joined: 19 Jul 2010
Total Posts: 889
19 Nov 2013 07:51 PM
This is the script I used, it was given to me by someone a few minutes ago, I can't remember their name. Anyway:

game.Players.PlayerRemoving:connect(function(player)
player:SaveInstance("Tools", player.Backpack)
end)

game.Players.PlayerAdded:connect(function(plr)
for _,n in pairs(plr:LoadInstance("Tools"))
n:Clone().Parent = plr.StarterGear
n:Clone().Parent = plr.Backpack
end
end)


There are no errors in output or anything like that. It doesn't save tools after a player leaves and enters.

Electrus Imperium shall prevail!
Report Abuse
Adam2090 is not online. Adam2090
Joined: 19 Jul 2010
Total Posts: 889
19 Nov 2013 07:54 PM
b

Electrus Imperium shall prevail!
Report Abuse
notsopwnedg is not online. notsopwnedg
Joined: 07 Nov 2010
Total Posts: 4182
19 Nov 2013 07:56 PM
I made a mistake. Sorry. Try this.

game.Players.PlayerRemoving:connect(function(player)
player:SaveInstance("Tools", player.Backpack)
end)

game.Players.PlayerAdded:connect(function(plr)
for _,n in pairs(plr:LoadInstance("Tools"):GetChildren())
n:Clone().Parent = plr.StarterGear
n:Clone().Parent = plr.Backpack
end
end)
Report Abuse
crouton04 is not online. crouton04
Joined: 07 Jul 2010
Total Posts: 4459
19 Nov 2013 07:57 PM
for i,v in pairs(player.Backpack:GetChildren()) do
i = i + 1
player:SaveInstance("Tools"..i,v)
end
Report Abuse
notsopwnedg is not online. notsopwnedg
Joined: 07 Nov 2010
Total Posts: 4182
19 Nov 2013 07:58 PM
Crouton why would you do that? Why?
There is no reason...
Report Abuse
Adam2090 is not online. Adam2090
Joined: 19 Jul 2010
Total Posts: 889
19 Nov 2013 08:00 PM
@not
Line 7 do expected near 'n'

Electrus Imperium shall prevail!
Report Abuse
crouton04 is not online. crouton04
Joined: 07 Jul 2010
Total Posts: 4459
19 Nov 2013 08:01 PM
tab = {}

game.Players.PlayerRemoving:connect(function(player)
for i,v in pairs(player.Backpack:GetChildren()) do
i = i + 1
table.insert(tab,i)
player:SaveInstance("Tools"..i,v)
end
end)

game.Players.PlayerAdded:connect(function(plr)
for l = 1,#tab do
n = player:LoadInstance("Tools"..i)
n:Clone().Parent = plr.StarterGear
n:Clone().Parent = plr.Backpack
end
end)
Report Abuse
crouton04 is not online. crouton04
Joined: 07 Jul 2010
Total Posts: 4459
19 Nov 2013 08:02 PM
I forgot to read to your whole script im tired. Anyway if theres no minor errors mine should work.
Report Abuse
notsopwnedg is not online. notsopwnedg
Joined: 07 Nov 2010
Total Posts: 4182
19 Nov 2013 08:03 PM
Crouton that wouldn't work unless you saved tab to the player also.

Another stupid mistake.

game.Players.PlayerRemoving:connect(function(player)
player:SaveInstance("Tools", player.Backpack)
end)

game.Players.PlayerAdded:connect(function(plr)
for _,n in pairs(plr:LoadInstance("Tools"):GetChildren()) do
n:Clone().Parent = plr.StarterGear
n:Clone().Parent = plr.Backpack
end
end)
Report Abuse
Bebee2 is not online. Bebee2
Joined: 17 May 2009
Total Posts: 3985
19 Nov 2013 08:03 PM
-- Umg I'll just rewrite the script. JSON may not work with Instances. Never tried. Better to just ignore this, actually.

Util = assert(LoadLibrary("RbxUtility"))


game.Players.PlayerAdded:connect(function(plr)
for _,tool in pairs(Util.DecodeJSON(plr:LoadString("Tools"))) do
tool:clone().Parent = plr.Backpack -- May not work.
tool:clone().Parent = plr.StarterGear -- May not work.
end

plr.Backpack.ChildAdded:connect(function()
local tools = Utils.EncodeJSON(plr.Backpack:GetChildren())
if player then
plr:WaitForDataReady()
plr:SaveString("Tools", tools)
end
end)
end)
Report Abuse
notsopwnedg is not online. notsopwnedg
Joined: 07 Nov 2010
Total Posts: 4182
19 Nov 2013 08:06 PM
Why do you both feel the need to rewrite my script...

There was just two stupid errors in it.(Or more.)

Report Abuse
crouton04 is not online. crouton04
Joined: 07 Jul 2010
Total Posts: 4459
19 Nov 2013 08:10 PM
True

tab = {}

game.Players.PlayerRemoving:connect(function(player)
for i,v in pairs(player.Backpack:GetChildren()) do
i = i + 1
table.insert(tab,i)
player:SaveInstance("Tools"..i,v)
end
crouton04 = setmetatable({},_G.tab)
strin = unpack(crouton04)
player:SaveString("str",strin)
end)

game.Players.PlayerAdded:connect(function(plr)
tab = player:LoadString("str")
for l = 1,#tab do
n = player:LoadInstance("Tools"..i)
n:Clone().Parent = plr.StarterGear
n:Clone().Parent = plr.Backpack
end
end)
Report Abuse
Adam2090 is not online. Adam2090
Joined: 19 Jul 2010
Total Posts: 889
19 Nov 2013 08:10 PM
I tried all of the submitted codes and none of them seemed to work.

Electrus Imperium shall prevail!
Report Abuse
crouton04 is not online. crouton04
Joined: 07 Jul 2010
Total Posts: 4459
19 Nov 2013 08:10 PM
That probably doesnt work, i'm very tired.
Report Abuse
crouton04 is not online. crouton04
Joined: 07 Jul 2010
Total Posts: 4459
19 Nov 2013 08:11 PM
Lol forgot to WaitForDataReady()
Report Abuse
crouton04 is not online. crouton04
Joined: 07 Jul 2010
Total Posts: 4459
19 Nov 2013 08:12 PM
tab = {}

game.Players.PlayerRemoving:connect(function(player)
plr:WaitForDataReady()
for i,v in pairs(player.Backpack:GetChildren()) do
i = i + 1
table.insert(tab,i)
player:SaveInstance("Tools"..i,v)
end
crouton04 = setmetatable({},_G.tab)
strin = unpack(crouton04)
player:SaveString("str",strin)
end)

game.Players.PlayerAdded:connect(function(plr)
plr:WaitForDataReady()
tab = player:LoadString("str")
for l = 1,#tab do
n = player:LoadInstance("Tools"..i)
n:Clone().Parent = plr.StarterGear
n:Clone().Parent = plr.Backpack
end
end)
Report Abuse
notsopwnedg is not online. notsopwnedg
Joined: 07 Nov 2010
Total Posts: 4182
19 Nov 2013 08:13 PM
Oooh I forgot that too D:
Report Abuse
crouton04 is not online. crouton04
Joined: 07 Jul 2010
Total Posts: 4459
19 Nov 2013 08:13 PM
tab = {}

game.Players.PlayerRemoving:connect(function(player)
plr:WaitForDataReady()
for i,v in pairs(player.Backpack:GetChildren()) do
i = i + 1
table.insert(tab,i)
player:SaveInstance("Tools"..i,v)
end
crouton04 = setmetatable({},_G.tab)
strin = unpack(crouton04)
player:SaveString("str",strin)
end)

game.Players.PlayerAdded:connect(function(plr)
plr:WaitForDataReady()
tab = {player:LoadString("str")}
for l = 1,#tab do
n = player:LoadInstance("Tools"..i)
n:Clone().Parent = plr.StarterGear
n:Clone().Parent = plr.Backpack
end
end)
Report Abuse
notsopwnedg is not online. notsopwnedg
Joined: 07 Nov 2010
Total Posts: 4182
19 Nov 2013 08:14 PM
game.Players.PlayerRemoving:connect(function(player)
player:SaveInstance("Tools", player.Backpack)
end)

game.Players.PlayerAdded:connect(function(plr)
plr:WaitForDataReady()
for _,n in pairs(plr:LoadInstance("Tools"):GetChildren()) do
n:Clone().Parent = plr.StarterGear
n:Clone().Parent = plr.Backpack
end
end)
Report Abuse
crouton04 is not online. crouton04
Joined: 07 Jul 2010
Total Posts: 4459
19 Nov 2013 08:14 PM
anyway my script is very inefficient for this perpose but could be used for something more complicated.
Report Abuse
crouton04 is not online. crouton04
Joined: 07 Jul 2010
Total Posts: 4459
20 Nov 2013 02:31 PM
tab = {}

game.Players.PlayerRemoving:connect(function(player)
plr:WaitForDataReady()
for i,v in pairs(player.Backpack:GetChildren()) do
i = i + 1
table.insert(tab,i)
player:SaveInstance("Tools"..i,v)
end
crouton04 = setmetatable({},tab)
strin = unpack(crouton04)
player:SaveString("str",strin)
end)

game.Players.PlayerAdded:connect(function(plr)
plr:WaitForDataReady()
tab = {player:LoadString("str")}
for l = 1,#tab do
n = player:LoadInstance("Tools"..i)
n:Clone().Parent = plr.StarterGear
n:Clone().Parent = plr.Backpack
end
end)
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