Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Data saving works in loop but not on playerremoving?

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!

1 comment

0

ROBLOX Studio is a bit bleh when it comes to data saving. Try playing the game from the website, might work.

2 answers

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!

1 comment

0

Thanks but I even tried 30 seconds and it does not take 30 seconds to setasync :D

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

This discussion is preserved as it was. New answers, comments, and votes are closed.