Should I use PlayerRemoving or Changed when saving a player's data with the DataStoreService?

Does using PlayerRemoving or Changed when saving data with DataStoreService make a difference? I’ve only recently started using DataStoreService, but I’ve seen that some people use PlayerRemoving and others use Changed. I’m not sure which is more sensible.

For PlayerRemoving
This Event Activates when the Player is Leaving the game, so when they do, you obviously want to save their Hard Work!

For Changed
I wouldn’t exactly recommend it, mainly due to queue’s, you can only Update Data for a certain amount of time, do it too much, and it will be dropped, Honestly, You can use both if you like, really up to you

Well, the “Changed” event will fire if anything has changed in the player instance. The “PlayerRemoving” is more reliable as it only fires upon player leaving and I think there is no need to get a changed signal to save player data.

True, but there is a slight issue to this, the data doesn’t save all the time, sometimes the player leaves before the code within the Event fires (Which is a good Example for Data Loss), pcall is valid but it isn’t perfect either.


If you dont know what pcall is: (This is a sort of advanced topic, I recommend reading about it Here.)

pcall essentially just means Protected Call, What it does its to prevent errors from occurring

xpcall is a Custom Error Handler
ypcall is a Deprectated Global (Discontinued, and is no longer supported) with the new Alternative pcall

Example of pcall:

local Success, ErrorString = pcall(function()
print("pcall Worked")
end)

if Success then
print("Successful")
else
warn(ErrorString)
end

Example of an Error:

local Success, ErrorString = pcall(function()
print(pcall Worked)
end)

if Success then
print("Successful")
else
warn(ErrorString)
end
1 Like

Both Changed and GetPropertyChangedSignal to the same thing.
(I think GetPropertyChangedSignal is better with change detection’s)

The only real difference is that GetPropertyChangedSignal looks for changes with one property instead of all like Changed

1 Like

Sorry, I meant to ask if using Changed or GetPropertyChangedSignal would be preferable to using PlayerRemoving since PlayerRemoving may result in data loss.

Either one works well,

The Only real issue is:

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.