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: Inventory Data Persistence

Previous Thread :: Next Thread 
iDemum is not online. iDemum
Joined: 17 Jan 2010
Total Posts: 56
20 Jul 2014 06:12 PM
Hello, I have a script test, that uses data persistence, so when a user clicks it then rejoins, it clones it and makes it 2 points above the original block. So what I need help with is for someone to change that so it will save there inventory, so if they pick up a weapon and click it then rejoin they will still have the weapon. Here is the code. Ill add comments where you have to change it . Thanks.

local Brick = script.Parent
local Key = "Part"
local Message = Instance.new("Message")
game.Players.PlayerAdded:connect(function(Player)
Player:WaitForDataReady()
local Object = Player:LoadInstance(Key)
if (Object ~= nil) then
Object.Parent = game.Workspace
Object.Anchored = true
Object.CFrame = CFrame.new(Brick.Positin+Vector3.new(0,2,0)) --this line above makes it another brick and saves.
Message.Text = "Success"
Message.Parent = game.Workspace
wait(5)
Message:Remove()

end
end)

game.Players.PlayerRemoving:connect(function(Player)
Player:SaveInstance(Key, Brick)


Thanks!
end)
Report Abuse
Notunknown99 is not online. Notunknown99
Joined: 05 Sep 2008
Total Posts: 25360
20 Jul 2014 06:13 PM
Positin

I sense a typo.
Report Abuse
Notunknown99 is not online. Notunknown99
Joined: 05 Sep 2008
Total Posts: 25360
20 Jul 2014 06:14 PM
Also, in future you should use F9 (online output)
Report Abuse
iDemum is not online. iDemum
Joined: 17 Jan 2010
Total Posts: 56
20 Jul 2014 06:15 PM
Thanks.
Report Abuse
iDemum is not online. iDemum
Joined: 17 Jan 2010
Total Posts: 56
20 Jul 2014 06:16 PM
But I still need to change it, so I don't really need that part.
Report Abuse
Notunknown99 is not online. Notunknown99
Joined: 05 Sep 2008
Total Posts: 25360
20 Jul 2014 06:17 PM
But had you opened the output, you would have seen the error and corrected it ;)
Report Abuse
iDemum is not online. iDemum
Joined: 17 Jan 2010
Total Posts: 56
20 Jul 2014 06:23 PM
Well you can only test it in Play mode, so I couldn't test for errors. xD
Report Abuse
Notunknown99 is not online. Notunknown99
Joined: 05 Sep 2008
Total Posts: 25360
20 Jul 2014 06:23 PM
F9 is an online output ;D
Report Abuse
iDemum is not online. iDemum
Joined: 17 Jan 2010
Total Posts: 56
20 Jul 2014 06:28 PM
Ok, well I need a real script help now xD I didn't need fixes I need what I asked xD xD
Report Abuse
BothAngles is not online. BothAngles
Joined: 01 Dec 2011
Total Posts: 9604
20 Jul 2014 06:29 PM
i have a script that does this
and it saves ur backpack for when u respawn

easy to make
Report Abuse
Notunknown99 is not online. Notunknown99
Joined: 05 Sep 2008
Total Posts: 25360
20 Jul 2014 06:33 PM
Oh, right.

Don't save their weapon's Instance, as that will eat your data cost.

Instead store all the names of the weapons in a table, like so:

local weapons = {}
for i, v in next, player.StarterGear:GetChildren() do
weapons[i] = v.Name
end

and then use HttpService:JSONEncode(string) to encode it into a string and use SaveString, then use LoadString and HttpService:JSONDecode(string) to get the table back, then iterate through it and clone the weapons from ServerStorage into their Backpack/StarterGear.
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