I cannot for the life of me understand messagingservice/memorystoreservice

Basically the title. I am trying to make a shop system similar to grow a garden; that is, all the servers update at the same time with the same stock. I already made a localized version of it but I can’t understand how I make it so that multiple servers don’t update it.

Is it possible for someone to make a visualization for how messaging service works and how memorystoreservice locks the updating? I’m a visual learner so it would help a lot.

It doesn’t have to be perfect lol

3 Likes

Roblox actually has a resource which does exactly what you’re looking for: https://create.roblox.com/store/asset/13595031529 (sourced from https://create.roblox.com/docs/samples).

4 Likes

Memorystoreservice shares a piece of temporary piece of data between all servers that lasts like 30 days, which can be stored in a queue (like people waiting in a line but the people are blocks of data), hashmap (like a dictionary that maps words to pieces of data) and sortedmap, which is hashmap but sorted

Im not sure how you would use messagingservice here
Messaging service sends a message from one server to all the other servers

You could probably just query the hashmap every 2 seconds (you get 120 per player + 1000 base)
Or maybe messagingservice tells servers when someone bought an item so they can query the hashmap and update only then

Heres my drawing of how it works

Edit: Actually you would probably have to use UpdateAsync on the hashmap to check if there is enough for every purchase

4 Likes

I’m not sure if I’m understanding correctly but basically you’re saying memorystore is like a simplified datastore for cross-server communication? I only want the stock data to be replicated on all servers and not the player buying it. every player gets their own stock they can buy but its the same.

I’m just wondering how I could interact with the memory store in section I circled below:

edit: how would I make it so that only one server updates?

memory store hashmaps work exactly like datastore (string → values) but the only difference is that memory stores are temporary and more optimized for short term use

if you want the stock data to be replicated but every player has their own stock
then i think you can just use a predictable seeded rng so you dont actually have to send anything. For example if you want it to reset every day, then the start of each day has a unique timestamp which you can put into RNG = Random.new(timestamp) to generate stock randomly by using the rng like

local randomNumber = RNG:NextNumber() -- returns between [0,1] but it will be the same for all servers since they have the same seed

If you only want “one server” to interact with memory stores or data stores i think the best way is to set up your own server and then use the opencloud API to interact with stuff (you can use your own computer if you turn it on all the time)
https://create.roblox.com/docs/cloud/reference/features/storage