Question about the cross server messaging tutorial example

The tutorial here Cross-Server Messaging

Sends a message whenever a player joins and the other script subscribes to the topic whenever a player gets added and then unsubscribes if the ancestry changes.

I am not sure though if that script in the guide is duplicating the amount of subscription to the “FriendServerEvent”

but… eitherways

Now, since there’s a script that publishes the message and another script that subscribes to the message. How is it ensured that it works?

Because, what happens if it first sends the message with “PublishAsync” before the other script even called “SubscribeAsync”?

What I tested, is that if you first send the PublishAsync, without being subscribed to the topic sending to, it won’t receive it, obviously. So I am not quite sure about that tutorial in that wiki.

How is that supposed to be handled instead?

1 Like

Use a GlobalDataStore and have each server check the message from time to time. I did something like this with GetKeyValue() in Code.org multiple times.

1 Like

So how would it exactly work?

I was triyng to figure out a better solution for the thing in the tutorial. Like, how to improve the tutorial.

One of my idea is to just put a SubscribeAsync in a separate script that constantly listens to the topic and nothing else.

1 Like

It very much is not the best solution because it requires constant grabbing and delays the script, so I suggest using it as a separate script:
Script in any place possible:

--setting it on one script
local datastore = game:GetService("DataStoreService"):GetDataStore("Message")
datastore:SetAsync("SentMessage", "Hello World!")

Script in ServerScriptStorage:

--getting it on another
local senddata = game:GetService("ReplicatedStorage").RemoteEvent
local datastore = game:GetService("DataStoreService"):GetDataStore("Message")
while wait() do
	local success, data = pcall(function()
		return datastore:GetAsync("SentMessage")
	end)
	if not success then
		repeat
			local success, data = pcall(function()
				return datastore:GetAsync("SentMessage")
			end)
		until success
	end
	if data then
		--if data found, then send it and reset the message
		senddata:FireAllClients(data)
		--should fire on all clients "Hello World!" based on the setting from top script
		datastore:SetAsync("SentMessage", nil)
	end
end

But one thing is for sure, it’s a lot more complex than on Code.org’s Game Lab.

1 Like

Thats completely wrong, you are sending requests multiple times (GetAsync and SetAsync) this will throw a lot of warnings then errors.

Please see the datastore limits below
image

1 Like

Except, I have no idea how to get the amount of requests sent… yet…

Using :GetAsync once = 1 Request sent to roblox server
Using :GetAsync 2 times = 2 Requests sent to roblox server

You are using a infinite loop, which will send infinite amount of requests, until the loop is stopped.

1 Like

Which is why this format is very unreliable. That is why i said at the start:

It was a lot easier on Code.org.