|
| 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 |
|
|
| |
|
|
| 15 Apr 2014 04:54 PM |
b2
The instance is a child of plr along with the int value. |
|
|
| Report Abuse |
|
|
|
| 15 Apr 2014 04:55 PM |
| make it a regular script inside Workspace |
|
|
| Report Abuse |
|
|
|
| 15 Apr 2014 04:57 PM |
| It is a regular script, but it is in the ServerScriptService. |
|
|
| Report Abuse |
|
|
|
| 15 Apr 2014 05:03 PM |
| Why not try using data stores? |
|
|
| Report Abuse |
|
|
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
|
  |
| 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 |
|
|
|
| 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 |
|
|
|
| 15 Apr 2014 05:11 PM |
| 'cash' is a string defined at the top of the script that I posted. |
|
|
| Report Abuse |
|
|
| |
|
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
|
  |
| 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
|
  |
| 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 |
|
|
|
| 15 Apr 2014 05:36 PM |
| The Data Persistence is working now. |
|
|
| Report Abuse |
|
|