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: DataPersistence not working

Previous Thread :: Next Thread 
robokittydestroyer is not online. robokittydestroyer
Joined: 20 Jul 2010
Total Posts: 311
15 Apr 2014 04:44 PM
I'm using data persistence to save a intvalue and and instance, but when I press either of the buttons, nothing happens. I'm getting no output. Script is below.


--Keys
cashKey = "PlrCash"
storeKey = "Backpack"

game.Players.PlayerAdded:connect(function(plr)
plr:WaitForChild('PlayerGui')
local gui = plr.PlayerGui.UserGui
local frame = gui.PackContents

frame.LoadButton.MouseButton1Click:connect(function()
if plr:WaitForDataReady() then
plr:SaveNumber(cashKey,cash)
plr:SaveInstance(storeKey,plr.Pack)
plr.PlayerGui.UserGui.PackContents.SaveButton.Text = "Success!"
else
plr.PlayerGui.UserGui.PackContents.SaveButton.Text = "Cannot save data."
end
wait(1)
plr.PlayerGui.UserGui.PackContents.SaveButton.Text = "Save Stats"
end)

frame.SaveButton.MouseButton1Click:connect(function()
if plr:WaitForDataReady() then
plr:LoadNumber(cashKey)
plr:LoadInstance(storeKey)
plr.PlayerGui.UserGui.PackContents.LoadButton.Text = "Success!"
else
plr.PlayerGui.UserGui.PackContents.LoadButton.Text = "Cannot save data."
end
wait(1)
plr.PlayerGui.UserGui.PackContents.LoadButton.Text = "Load Stats"
end)
end)
Report Abuse
robokittydestroyer is not online. robokittydestroyer
Joined: 20 Jul 2010
Total Posts: 311
15 Apr 2014 04:50 PM
b1
Report Abuse
robokittydestroyer is not online. robokittydestroyer
Joined: 20 Jul 2010
Total Posts: 311
15 Apr 2014 04:54 PM
b2

The instance is a child of plr along with the int value.
Report Abuse
SenseiWarrior is not online. SenseiWarrior
Joined: 09 Apr 2011
Total Posts: 12140
15 Apr 2014 04:55 PM
make it a regular script inside Workspace
Report Abuse
robokittydestroyer is not online. robokittydestroyer
Joined: 20 Jul 2010
Total Posts: 311
15 Apr 2014 04:57 PM
It is a regular script, but it is in the ServerScriptService.
Report Abuse
Fluffmiceter is not online. Fluffmiceter
Joined: 28 Jan 2012
Total Posts: 6931
15 Apr 2014 05:03 PM
Why not try using data stores?
Report Abuse
Bebee2 is not online. Bebee2
Joined: 17 May 2009
Total Posts: 3985
15 Apr 2014 05:09 PM
--Keys
cashKey = "PlrCash"
storeKey = "Backpack"

game.Players.PlayerAdded:connect(function(plr)
plr:WaitForChild('PlayerGui')
local gui = plr.PlayerGui:WaitForChild'UserGui'
local frame = gui:WaitForChild'PackContents'

frame.SaveButton.MouseButton1Click:connect(function()
local succ = pcall(function() plr:WaitForDataReady()
plr:SaveNumber(cashKey,cash)
plr:SaveInstance(storeKey,plr.Pack) -- What is this plr.Pack?
end)
if succ then
plr.PlayerGui.UserGui.PackContents.SaveButton.Text = "Success!"
else
plr.PlayerGui.UserGui.PackContents.SaveButton.Text = "Cannot save data."
end
wait(1)
plr.PlayerGui.UserGui.PackContents.SaveButton.Text = "Save Stats"
end)

frame.LoadButton.MouseButton1Click:connect(function()

local succ = pcall(function()
plr:WaitForDataReady()
whatever = plr:LoadNumber(cashKey) -- Set this to something.
plr:LoadInstance(storeKey).Parent = plr -- I guess...?
if succ then
plr.PlayerGui.UserGui.PackContents.LoadButton.Text = "Success!"
else
plr.PlayerGui.UserGui.PackContents.LoadButton.Text = "Cannot save data."
end
wait(1)
plr.PlayerGui.UserGui.PackContents.LoadButton.Text = "Load Stats"
end)
end)
Report Abuse
Bebee2 is not online. Bebee2
Joined: 17 May 2009
Total Posts: 3985
15 Apr 2014 05:10 PM
Oh and

plr:SaveNumber(cashKey,cash)


What is this cash?
Report Abuse
robokittydestroyer is not online. robokittydestroyer
Joined: 20 Jul 2010
Total Posts: 311
15 Apr 2014 05:10 PM
I already checked out that option, but I find it difficult to work with in my game.
Report Abuse
robokittydestroyer is not online. robokittydestroyer
Joined: 20 Jul 2010
Total Posts: 311
15 Apr 2014 05:11 PM
'cash' is a string defined at the top of the script that I posted.
Report Abuse
robokittydestroyer is not online. robokittydestroyer
Joined: 20 Jul 2010
Total Posts: 311
15 Apr 2014 05:13 PM
Forgot to define cash.
Report Abuse
Bebee2 is not online. Bebee2
Joined: 17 May 2009
Total Posts: 3985
15 Apr 2014 05:17 PM
And what is this plr.Pack?

Why did you swap the Save button with the Load button ( I fixed that for you except I didn't change the error message)?

How come you didn't set the loaded data to something (I pointed that out)?
Report Abuse
BladeXE is not online. BladeXE
Joined: 22 Dec 2012
Total Posts: 3857
15 Apr 2014 05:19 PM
scripts don't run in serverscriptstorage
only playerGui and Workspace
Report Abuse
Bebee2 is not online. Bebee2
Joined: 17 May 2009
Total Posts: 3985
15 Apr 2014 05:26 PM
Server scripts run in ServerScriptStorage






I do it for something like a minigame.
Report Abuse
robokittydestroyer is not online. robokittydestroyer
Joined: 20 Jul 2010
Total Posts: 311
15 Apr 2014 05:36 PM
The Data Persistence is working now.
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