Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Data saving works in loop but not on playerremoving?

Asked by 8 years ago

Hi guys!

I know the save function works because it works like so:

while wait(5) do
    for k,v in pairs(Players:GetPlayers()) do ---THIS WORKS
         save(v,"PlayerData")
    end
end

Any ideas why it doesn't work like this??

Players.PlayerRemoving:connect(function(plr)
         save(plr,"PlayerData")
end)

game.OnClose = function()
wait(5)
end

--To make sure it has enough time to save! It can't be that!


With prints, it gets halfway through the saving data and then just seems to... stop. I cannot understand why!!

Any ideas would be greatly appreciated! Thanks!

0
ROBLOX Studio is a bit bleh when it comes to data saving. Try playing the game from the website, might work. joalars2 107 — 8y

2 answers

Log in to vote
0
Answered by 8 years ago

I can't see why it's stopping, but it might be because you have the wait(5) line in there. Try replacing with a command that says "wait until done" if possible. Hope this helps!

0
Thanks but I even tried 30 seconds and it does not take 30 seconds to setasync :D jjwood1600 215 — 8y
Ad
Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

In lines 5 to 7, change from using .OnClose to :BindToClose(). The OnClose property is deprecated.

Check out how the function works here.

Players.PlayerRemoving:connect(function(plr)
         save(plr,"PlayerData")
end)

game:BindToClose(function() -- BindToClose basically makes the function run when the server shuts down.
    wait(5)
    print("Done! Shutting down...")
end)

If you test it out in Studio, it will wait for 5 seconds and print, "Done! Shutting down..." in the output before stopping the test.

If you have any questions or problems, list them in the comments below. Thanks! :D

Answer this question