How would I update the game via servers? (Like Note Placing Games)

Hello! This is my first post!

I was wondering how I would go about servers updating the game, for example in one server, player places a block, leaves, and then another player joins a new server and sees that block. Like note placing games such as a dream youve had before - Roblox and your last thoughts at the end of time - Roblox

The problem is I have no idea how to do that. I was thinking about using messaging service, but would that mean that the stuff players created would be gone after the servers are all empty? I do not know very much about messaging service so please correct me if I am wrong. I can give more information if necessary.

Thank you!

1 Like

You’d need to be storing data using the DataStoreService if you want everything to save after all servers are empty, and then you can either use the MessagingService or you can use external webhooks to communicate with other servers and tell them to update their workspace.

Here is an example:

local DataStoreService = game:GetService("DataStoreService")
local MessagingService = game:GetService("MessagingService")

local Block_DataStore = DataStoreService:GetDataStore("blocks")

local blocks = {
    grass = ServerStorage:FindFirstChild("GrassBlock"),
    stone = ServerStorage:FindFirstChild("StoneBlock"),
    dirt = ServerStorage:FindFirstChild("DirtBlock")
}

-- So first you need to "subscribe" to the topic you want to listen to,
-- in this case, it would be called something like "blocks".

local topic = "blocks"

local connection = MessageService:SubscribeAsync(topic, function(blockType, blockPosition)
    -- This function will now be called every time this topic receives a message.
    -- You will probably want your message to contain block type and block position.
    -- You can then add this block to the workspace.
    
    local block = blocks[blockType]
    local blockClone = block:Clone()
    blockClone.Parent = workspace
    blockClone.Position = blockPosition
end)

-- Now to send new messages we can write a function that can be called every
-- time a new block is placed.

function newBlock(blockType, blockPosition)
    -- Then we can send the message
    MessageService:PublishAsync(topic, blockType, blockPosition)

    -- Now all servers can update their workspace when a player places a block.
    -- But we also want to store this block and its position.
    -- To do this we can use the "Block_DataStore" that I initialized earlier.
    -- I will set the key of the store to the position, and the value to the type.
    Block_DataStore:SetAsync(blockPosition, blockType)
end

-- Now when your server starts up all you need to do is iterate through 
-- the "Block_DataStore" to load all the player-placed blocks into the server.

I hope you found this helpful, but this is by no means a perfect piece of code and you should only use this as an example.

You technically don’t need MessagingService.

You can simply update a server by checking every random amount of time, say 60 seconds, and update the notes. You can add only new ones by giving every note a unique ID when made, like 1 to a million, and when loading, if that ID isn’t found in the game, add it. With the ID, the entire game won’t just refresh.

That way, all notes are loaded on a new server, and you create less lag by not using MessagingService and only adding new notes in.

Sure, but if you want it to update in real time, then MessagingService is necessary.

That worked!
I had to make a few changes for it to work for what I wanted, but it helped me immensely nonetheless! Hopefully some of the stuff I learned will help me in the future!

That’s great to hear! I’m glad I could be of help to you.

Actually, now that I’m experimenting more with it, I’ve run into a problem.
On line 17, for whatever reason the function will interpret the second variable (blockPosition) as nil. I’m not sure if I’m doing something wrong or what. I’ve tried a couple different ways and it’s always been interpreted as nil.

Nevermind! Fixed it! I didn’t realize messagingservice wouldn’t let me do 2 variables. It’s fixed and working now though!