Help with using Memory Store

Hello,
I am trying to learn how to use Memory Store, I am having trouble figuring out how to use SetAsync() and the other fuctions. If someone could explain to me how to use them that would be amazing!

My Script at the moment:

game.Players.PlayerAdded:Connect(function(plr)
local MemoryService = game:GetService("MemoryStoreService")
local SecretsHatched = MemoryService:GetSortedMap("SecretHatches")
local Secrets = plr:WaitForChild("Secrets")

--Secrets
local UniThing = SecretsHatched:SetAsync(?????)
2 Likes

Maybe this will help:

EDIT: After reading this, it would go like this:

local UniThing = SecretsHatched:SetAsync('Store to use', 'Value to set')
1 Like

Basically SortedMaps function like regular DataStores, except they have a storage and time limit. When using the functions SetAsync() and UpdateAsync(), it requires a key and value perimeter, similar to DataStores, as well as a final expiration perimeter, which is basically when the data removes itself (in seconds). GetAsync() and RemoveAsync() is the exact same as DataStores, which only requires a key.

1 Like

Oh sweet, Thank you so much. If I were using this to have data across multiple servers would I set it to expire quickly or take a bit longer?

Thank you so much for the help.

Well, this depends on how active your game is. In your scenario I would suggest just setting it to maximum (30 days or 2,592,000s) unless you really need it to be removed earlier to clear space.

1 Like

Oh alright thank you, But to update it, Would it update across all servers when they GetAsync()?

Yes, MemoryStore is able to be read in any server relating to the game.

1 Like

Awesome thank you so much for your help!