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 problem

Previous Thread :: Next Thread 
Cheater is not online. Cheater
Joined: 29 Jun 2007
Total Posts: 5258
05 Feb 2012 10:37 AM
Hello bodies

I've got the problem that my servers sometimes lose connection and the data persistance won't save for anyone. Now I wanted to ask if it's possible to make the data persistance save every second and not when player leave. The script looks like this for now:



function PA(player)
wait(1)
player:WaitForDataReady()
if game.Workspace:FindFirstChild("Shopping"):findFirstChild(player.Name) then
plot = game.Workspace:FindFirstChild("Shopping"):findFirstChild(player.Name):GetChildren()
for p = 1,#plot do
plot[p].Value = player:LoadNumber(plot[p].Name)
end
end
end
game.Players.ChildAdded:connect(PA)

game.Players.PlayerRemoving:connect(function(oP)
for _,v in pairs(game.Workspace:FindFirstChild("Shopping"):findFirstChild(oP.Name):children()) do
oP:SaveNumber(v.Name, v.Value)
end
end)




Would it work when I write this:




function PA(player)
wait(1)
player:WaitForDataReady()
if game.Workspace:FindFirstChild("Shopping"):findFirstChild(player.Name) then
plot = game.Workspace:FindFirstChild("Shopping"):findFirstChild(player.Name):GetChildren()
for p = 1,#plot do
plot[p].Value = player:LoadNumber(plot[p].Name)
end
end
end
game.Players.ChildAdded:connect(PA)

while true do
for _,v in pairs(game.Workspace:FindFirstChild("Shopping"):findFirstChild(oP.Name):children()) do
oP:SaveNumber(v.Name, v.Value)
end
wait(1)
end

Report Abuse
kingkiller1000 is not online. kingkiller1000
Joined: 12 Dec 2008
Total Posts: 26415
05 Feb 2012 10:38 AM
Why on Earth do you need to save every second?
Report Abuse
Cheater is not online. Cheater
Joined: 29 Jun 2007
Total Posts: 5258
05 Feb 2012 10:47 AM
Because my servers sometimes lose connection and than it doesn't save.
Report Abuse
Cheater is not online. Cheater
Joined: 29 Jun 2007
Total Posts: 5258
05 Feb 2012 10:48 AM
Oh and the while true do thing doesn't work. I already tested it.
Report Abuse
Cheater is not online. Cheater
Joined: 29 Jun 2007
Total Posts: 5258
05 Feb 2012 10:55 AM
Is it even possible saving every second? I just remember the thing with for I = 1... but I think this also won't work.
Report Abuse
Cheater is not online. Cheater
Joined: 29 Jun 2007
Total Posts: 5258
05 Feb 2012 11:02 AM
Epic failed. I try this now:

function PA(player)
wait(1)
player:WaitForDataReady()
if game.Workspace:FindFirstChild("Shopping"):findFirstChild(player.Name) then
plot = game.Workspace:FindFirstChild("Shopping"):findFirstChild(player.Name):GetChildren()
for p = 1,#plot do
plot[p].Value = player:LoadNumber(plot[p].Name)
end
end
end
game.Players.ChildAdded:connect(PA)

while true do
thing = game.Players:GetChildren()
for i = 1,#thing do
game.Workspace:FindFirstChild("Shopping"):findFirstChild(thing[i].Name):children()) do
thing[i]:SaveNumber(v.Name, v.Value)
end
wait(1)
end

Report Abuse
MrCrazyman42 is not online. MrCrazyman42
Joined: 01 Feb 2011
Total Posts: 740
05 Feb 2012 11:07 AM
function onPlayerEntered(player)
wait()-- Give the game a moment to find the player instead of shooting instantly.
player:WaitForDataReady() -- Gotta have this
repeat wait() until player:FindFirstChild("leaderstats") -- waits for the stats.
if player.DataReady then -- A little pointless But whatever :)
if player:findFirstChild("leaderstats") then
local score = player.leaderstats:GetChildren() -- Were going to find some scores.
for i = 1,#score do
local ScoreLoaded = player:LoadNumber(score[i].Name) -- This looks for the score.
wait() -- Wait for the score to load.
if ScoreLoaded ~= 0 then
score[i].Value = ScoreLoaded
end
end
end
end
end

function onPlayerLeaving(player) -- We gotta fire this before the player leaves.
if player:findFirstChild("leaderstats") then
local score = player.leaderstats:GetChildren() -- Targeting the scores before the player is gone
for i = 1,#score do
player:SaveNumber(score[i].Name,score[i].Value) -- Saving the score.
end
end
end

game.Players.PlayerAdded:connect(onPlayerEntered)
game.Players.PlayerRemoving:connect(onPlayerLeaving)






There. Whenever you lose connection, you wont hae to save. It's an auto data persistance save script.
Report Abuse
Cheater is not online. Cheater
Joined: 29 Jun 2007
Total Posts: 5258
05 Feb 2012 11:09 AM
How stupid I am again....

This should work:






function PA(player)
wait(1)
player:WaitForDataReady()
if game.Workspace:FindFirstChild("Shopping"):findFirstChild(player.Name) then
plot = game.Workspace:FindFirstChild("Shopping"):findFirstChild(player.Name):GetChildren()
for p = 1,#plot do
plot[p].Value = player:LoadNumber(plot[p].Name)
end
end
end
game.Players.ChildAdded:connect(PA)

while true do
thing = game.Players:GetChildren()
for i = 1,#thing do
game.Workspace:FindFirstChild("Shopping"):findFirstChild(thing[i].Name):children() do
thing[i]:SaveNumber(v.Name, v.Value)
end
wait(1)
end
end

Report Abuse
MrCrazyman42 is not online. MrCrazyman42
Joined: 01 Feb 2011
Total Posts: 740
05 Feb 2012 11:11 AM
Or use mine....
Report Abuse
Cheater is not online. Cheater
Joined: 29 Jun 2007
Total Posts: 5258
05 Feb 2012 11:17 AM
Yours still has the thing when player get removed or leave so I think yours also won't work. Mine also doesn't work with the while true do. It doesn't even give an output error.
Report Abuse
Cheater is not online. Cheater
Joined: 29 Jun 2007
Total Posts: 5258
06 Feb 2012 12:44 PM
Still no ideas of anyone? Or did the thread just get lost. ._.
Report Abuse
AgentFirefox is not online. AgentFirefox
Top 100 Poster
Joined: 20 Jun 2008
Total Posts: 22404
06 Feb 2012 12:53 PM
function PA(player)
wait(1)
player:WaitForDataReady()
if game.Workspace:FindFirstChild("Shopping"):FindFirstChild(player.Name) then
plot = game.Workspace:FindFirstChild("Shopping"):FindFirstChild(player.Name):GetChildren()
for p = 1,#plot do
plot[p].Value = player:LoadNumber(plot[p].Name)
end
end
end
game.Players.PlayerAdded:connect(PA)

function SAVE(player)
for _,v in pairs(game.Workspace:FindFirstChild("Shopping"):findFirstChild(player.Name):GetChildren()) do
oP:SaveNumber(v.Name, v.Value)
end
end
game.Players.PlayerRemoving:connect(SAVE)

repeat
for _, v in pairs(game.Players:GetPlayers()) do
SAVE(v)
end
wait(1)
until Shutting_Down_Teh_Server_Connection_Loss_OMG -- leave this, it's important !!
Report Abuse
AgentFirefox is not online. AgentFirefox
Top 100 Poster
Joined: 20 Jun 2008
Total Posts: 22404
06 Feb 2012 12:53 PM
Woops.




function PA(player)
wait(1)
player:WaitForDataReady()
if game.Workspace:FindFirstChild("Shopping"):FindFirstChild(player.Name) then
plot = game.Workspace:FindFirstChild("Shopping"):FindFirstChild(player.Name):GetChildren()
for p = 1,#plot do
plot[p].Value = player:LoadNumber(plot[p].Name)
end
end
end
game.Players.PlayerAdded:connect(PA)

function SAVE(player)
for _,v in pairs(game.Workspace:FindFirstChild("Shopping"):findFirstChild(player.Name):GetChildren()) do
player:SaveNumber(v.Name, v.Value)
end
end
game.Players.PlayerRemoving:connect(SAVE)

repeat
for _, v in pairs(game.Players:GetPlayers()) do
SAVE(v)
end
wait(1)
until Shutting_Down_Teh_Server_Connection_Loss_OMG -- leave this, it's important !!
Report Abuse
noobkid is not online. noobkid
Joined: 17 Sep 2007
Total Posts: 649
06 Feb 2012 01:05 PM
Couldn't you just change the value when it changes?
Report Abuse
Cheater is not online. Cheater
Joined: 29 Jun 2007
Total Posts: 5258
06 Feb 2012 01:15 PM
The script already works when I normally leave and come back. Now let's see if it also works when the server or I lose connection. I'll inform you as soon as this happens once again. Thank you for now.
Report Abuse
Cheater is not online. Cheater
Joined: 29 Jun 2007
Total Posts: 5258
06 Feb 2012 01:35 PM
The script doesn't even work everytime. Just sometimes it loads.
Report Abuse
Cheater is not online. Cheater
Joined: 29 Jun 2007
Total Posts: 5258
06 Feb 2012 02:24 PM
Right now it seems to be working for other people. I'm waiting for the losing connection thing...
Report Abuse
KnightmareXD is not online. KnightmareXD
Joined: 14 Jul 2009
Total Posts: 11189
06 Feb 2012 02:29 PM
Then force yourself to lose connection to test it.

† KMXD †
Report Abuse
Cheater is not online. Cheater
Joined: 29 Jun 2007
Total Posts: 5258
06 Feb 2012 02:40 PM
I can't do that when I want to. I need the exact version that happened before only than I know.
Report Abuse
AgentFirefox is not online. AgentFirefox
Top 100 Poster
Joined: 20 Jun 2008
Total Posts: 22404
06 Feb 2012 05:03 PM
You can force a loss in connection by manually shutting down the server.
Report Abuse
Cheater is not online. Cheater
Joined: 29 Jun 2007
Total Posts: 5258
07 Feb 2012 02:38 PM
No this says the server has shutdown and not you've lost the connection to the server.

Anyways. Following situation:

If I use the old script (at the very top of this thread) it perfectly saves and loads my stuff.
If I use your new script it only saves and loads when another guy starts the server. When I start a server, everything is set to 0 so I guess it doesn't load. Any ideas why?
Report Abuse
Cheater is not online. Cheater
Joined: 29 Jun 2007
Total Posts: 5258
07 Feb 2012 02:59 PM
It has been prooved that the new DP script from you doesn't always load the complete script. So maybe it is broken while the game starts or just stops working at a moment. And this is not only for me, it's also for other people. Sometimes the script works and sometimes not.
Report Abuse
Cheater is not online. Cheater
Joined: 29 Jun 2007
Total Posts: 5258
07 Feb 2012 03:05 PM
I think when I change the two scripts, they'll completly reset everyone's score but the new DP doesn't save and load 100%. The old just doesn't save/load when the connection gets lost. So there's a little problem I can never figure out with your new script.
Report Abuse
AgentFirefox is not online. AgentFirefox
Top 100 Poster
Joined: 20 Jun 2008
Total Posts: 22404
08 Feb 2012 06:06 AM
"No this says the server has shutdown and not you've lost the connection to the server. "

Functionally, it is the same thing.


"I think when I change the two scripts, they'll completly reset everyone's score but the new DP doesn't save and load 100%"

Changing the scripts will NOT reset the score.


"So maybe it is broken while the game starts or just stops working at a moment. And this is not only for me, it's also for other people. Sometimes the script works and sometimes not."

Then you have to take into consideration your conditional. Let's look at it:

------
wait(1)
player:WaitForDataReady()
if game.Workspace:FindFirstChild("Shopping"):FindFirstChild(player.Name) then
------

When the script doesn't work, workspace.Shopping.playerName doesn't exist. You could try waiting longer; I recommend 3-4 seconds.

What happens is, you have another script creating these shopping values, then this script runs in the background. Your shopping script is lagging behind in creating the values.
Report Abuse
Cheater is not online. Cheater
Joined: 29 Jun 2007
Total Posts: 5258
08 Feb 2012 07:48 AM
So the new part you added into the script makes it so terribly more laggy than before? Really strange how connection works. :/ That's absolutly true that the shopping script is another script. I'll try it.
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