Is it a good idea to :SetAsync() after each checkpoint?

So I have an obby that saves a player’s stage everytime they reach a new stage.
Although there really isn’t anything wrong with doing that, players on easy levels that touch checkpoints really quickly are setting the datastore key too quickly and I get something similar to this.

My question is - is it good practice to save a player’s data everytime they touch a new stage?

if touch.Parent == checkpoints then
		if (tonumber(touch.Name) and tonumber(touch.Name) > tonumber(stage.Value)) or touch.Name == "End" then
			stage.Value = touch.Name

			pcall(function()
					
				obbyDS:SetAsync(plr.UserId .. "-obbyStageProgress", plr.leaderstats.Stage.Value)

Keep in mind I also :SetAsync() when they leave the game

game.Players.PlayerRemoving:Connect(function(plr)

	pcall(function()

		obbyDS:SetAsync(plr.UserId .. "-obbyStageProgress", plr.leaderstats.Stage.Value)
	end)
end)

Any help is appreciated, thanks!

I would just increment their stage value every time they reach a checkpoint and save that to the data store when they leave. It’s too many requests if you call :SetAsync() after every single checkpoint.

4 Likes

So are you suggesting I just remove the pcall function and allow the game to save the player’s data only when they leave the game?

Not its not, just save it when they leave the game instead.

@OctaLua Do not leave it to save when they leave the game

@lluckvy You should update it every few minutes or stages.

why? whats the problem with it

What if saving on leave fails? Lose a session of progress or a few minutes of progress?

Could I add a wait(6) between the pcall function and the SetAsync()?

Maybe just add a save button and tell the user that the data successfully saved or not

No. There is a limit to SetAsync. Use UpdateAsync instead if you save data constantly.

UpdateAsync and SetAsync both have a cooldown of 6 seconds, therefore using UpdateAsync is redundant for saving data constantly.

But there is a limit for SetAsync that is why people use UpdateAsync instead of SetAsync if they have to keep on saving data.

Updating data every few stages is a really bad idea and inefficient. What if the player get’s too stages too fast?

Data should be saved only every 2-3 minutes, on player leave and when the server shutsdown.

Incorrect, both have a cooldown of 6 seconds for saving data for the same key. If OP decides to save data for let’s say P1 and P2, he should be good since OP won’t be saving the data for the same key.

Using UpdateAsync is good practice, since it respects conflicting calls and is really useful. It gives you the user’s old data, and that way you can check if the user has the same data and cancel the save effectively.

However, both SetAsync and UpdateAsync have the same cooldown.

1 Like

Yes, I know about the cool down. I am talking about the long term. UpdateAsync is more preferable for saving data

Edit: I personally would only use SetAsync if I am going to only change it a few times

is it good practice to save a player’s data everytime they touch a new stage?

No, it is bad practice.

Just save the player’s data on leave and on server shutdown. In a rare case where Player Removing doesn’t fire, you would need to implement auto saving every few minutes.

1 Like

This makes more sense there’s no point in saving it every stage the game would have to work harder.

Use a bindable event which prevents data losses. I learnt it from alvinblox’s video.

Would an autosave look something like this?

while true do 
   for _, player in ipairs(game:GetService("Players"):GetPlayers()) do
   pcall(function()
      obbyDS:SetAsync(plr.UserId .. "-obbyStageProgress", plr.leaderstats.Stage.Value)
      wait(5)
   end
   wait(120)
end

didn’t test code yet

I did not mean every two stages, I meant a bigger interval.