I’m trying to make my own data store system, and I’ve been using :OnUpdate to listen to data store changes, however this function has been deprecated for some time now, and I don’t like having deprecated things on my scripts because it gives off a bad look + it has some issues with it that makes me have to do extra work.
I’ve been looking for replacements for :OnUpdate, the most notable one being MessagingService which is even listed in the roblox documentation as a replacement for this function, but I simply don’t understand how I can make it work.
Any help is appreciated, just note I have never touched MessagingService before
Also please don’t share modules like DataStore2 or ProfileService, I want to make my own datastore system
There is no :OnUpdate Event in roblox’s DataStore, you are referring to third-party module.
There are many ways on doing this, but what I would do is wrap any update methods with custom function (overwriting previous function) and having your own event which you fire upon updating.
local dataStoreModule = <DataStore module>
dataStoreModule.OnUpdateEvent = Instance.new("BindableEvent")
dataStoreModule.OnUpdate = dataStoreModule.OnUpdateEvent.Event
--Not familiar with DataStore2, therefore I will provide pseudo-code
local function setAsync(keyIndex, value)
dataStore:SetAsync(keyIndex, value)
--DataStore2 should handle errors and such, replace this with custom function
onUpdateEvent:Fire(keyIndex, value)
--Fires event after setting value.
end
--Outside.
local dataStoreModule = <DataStore module>
local function onDataStoreUpdate(keyIndex, value)
--Do stuff with keyIndex and value.
end
dataStoreModule.OnUpdate:Connect(onDataStoreUpdate)
Huh… Well my solution should still work either way… You just need to wrap setAsync and others which update values, my method should still work even if it isn’t third-party module.
As far as I know, Roblox has not added an updated version of the OnUpdate event. I believe it was removed with the intention that developers would utilize MemoryStoreService, MessagingService, or would simply create a loop to get data and check if it’s any different than the last time it was retrieved. If you can explain more about the actual purpose, I may be able to help you further.
I’d honestly just wait it out until roblox releases the new version of Datastore, It’s (expected) to release later this year so It may just include functionality that’d be useful to you.
I left a link below for the roadmap and one of the staff had commented on it on a different post but I don’t remember where I seen it.
Thanks! Seems like the most viable solution will be waiting for the new version. But at least OnUpdate works fine for me even if I have to do extra work.
Well I’m just using OnUpdate for a leaderboard that updates with the datastore’s values. So if a player’s currency changes, the leaderboard will change too.
I already got it working with OnUpdate but I just don’t like the function being deprecated.
Yeah in reference to that I’d probably suggest using OrderedDatastore & just requesting it every 30 seconds or so, you really don’t need to update the leaderboard every time it updates as that’ll start getting costly if your game becomes larger.
If this is just normal data for a user store everything inside of a table in server and just cache it there and periodically autosave the data & when the user leaves ofc save the data and remove their cached data from the table in server.