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!
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!
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