MessagingService Issues?

I am developing a lobby system, and the whole concept of it is tat you are able to reserve servers as “rooms”, with the option to make it public (so the game shows up on server listings) or private(doesn’t show up on game listings, requires a password). In these games the host recieves a password which can be shared to anyone who wants to join. However, I am having trouble recieving key information from the server in time for the player handling to start.

Let me clarify this in more detail:

When I create the game in the lobby server it successfully publishes without any errors, and with the correct information, which makes me think that there is an obvious issue when it comes to me subscribing to the topic.

I have checked that the topics are the same and there are no errors, however on join it either kicks you or it just doesn’t prompt you, which isn’t what I want

CODE

Publishing End:

--PUBLISHING END--
local sendingTable ={
                    Password = "NA",
                    AccessCode = serverCode,
                    Difficulty = DataTable.Difficulty,
                    Host = Player.UserId
                }
                local stringMessage = sendingTable.Host.." "..sendingTable.Password.." "..sendingTable.Difficulty.." "..sendingTable.AccessCode
                print(stringMessage)
                local publishSuccess, publishResult = pcall(function()
                    MessagingService:PublishAsync(MessagingTopic, stringMessage)
                end)
                if publishSuccess then
                    print("Sent The Following Password To Server Access Code: "..sendingTable.AccessCode..": "..sendingTable.Password)

Recieving End

---RECIEVING ENG--
local Topic = "PASSWORD_SENDING"
local Host,Password
local isPrivate = false
local AccessCode
local String
local MessagingService = game:GetService("MessagingService")
local subscribeSuccess, subscribeConnection = pcall(function()
    return MessagingService:SubscribeAsync(Topic, function(message)
        String = message.Data
        local Table = string.split(String, " ")
        game.ReplicatedStorage.Difficulty.Value = Table[3]
        Password = Table[2]
        Host = Table[1]
        AccessCode =Table[4]
        print(Host, Password , Table.Difficulty)
        if Password == "NA" then
            isPrivate = false
        else
            isPrivate = true
        end
    end)
end)
if subscribeSuccess then
    subscribeConnection:Disconnect()
    game.Players.PlayerAdded:Connect(function(Player)
        if Host ~= nil then
            if Player.UserId == Host then
                game.ReplicatedStorage.promptStartScreen:FireClient(Player,Password, isPrivate)
            else
                if isPrivate then
                    game.ReplicatedStorage.promptPasscode:FireClient(Player)
                else
                    game.ReplicatedStorage.waitingEvent:FireClient(Player)
                end
            end
        else
            for index, Player in pairs(game.Players:GetPlayers()) do
                Player:Kick("Message sent from remote server failed. Please try again.")
            end
        end
    end)    
else
    for index, Player in pairs(game.Players:GetPlayers()) do
        Player:Kick("Error on the server side. Removing players.")
    end
end
 
 
game.ReplicatedStorage.promptStartScreen.OnServerEvent:Connect(function()
    game.ReplicatedStorage.isReady.Value = true
    game.ReplicatedStorage.startGame:FireAllClients()
end)
 
game.ReplicatedStorage.promptPasscode.OnServerEvent:Connect(function(Player, Code)
    if string.upper(Code) == string.upper(Password) then
        game.ReplicatedStorage.loginSuccessful:FireClient(Player)
    else
        Player:Kick("Failed to login.")
    end
end)

Help/?

However, I am having trouble recieving key information from the server in time for the player handling to start.

You say in time. Is it possible to wait until you receive said information before the player handling starts?

1 Like

I’ll try that and see what happens!

Well, I tried that and now it just never stops

local Topic = "PASSWORD_SENDING"
local Host,Password
local isPrivate = false
local AccessCode
local String
local MessagingService = game:GetService("MessagingService")
local subscribeSuccess, subscribeConnection = pcall(function()
	return MessagingService:SubscribeAsync(Topic, function(message)
		print("Recieved event!")
		String = message.Data
		local Table = string.split(String, " ")
		game.ReplicatedStorage.Difficulty.Value = Table[3]
		Password = Table[2]
		Host = Table[1]
		AccessCode =Table[4]
		print(Host, Password , Table.Difficulty)
		if Password == "NA" then
			isPrivate = false
		else
			isPrivate = true
		end
	end)
end)
if subscribeSuccess then
	game.Players.PlayerAdded:Connect(function(Player)
		repeat wait() until String ~= nil 
		if String ~= nil then
			game.ReplicatedStorage.disableLoadingUI:FireAllClients()
		end
		if Host ~= nil then
			if Player.UserId == Host then
				game.ReplicatedStorage.promptStartScreen:FireClient(Player,Password, isPrivate)
			else
				if isPrivate then
					game.ReplicatedStorage.promptPasscode:FireClient(Player)
				else
					game.ReplicatedStorage.waitingEvent:FireClient(Player)
				end
			end
		else
			for index, Player in pairs(game.Players:GetPlayers()) do
				Player:Kick("Message sent from remote server failed. Please try again.")
			end
		end
		subscribeConnection:Disconnect()
	end)	
else
	for index, Player in pairs(game.Players:GetPlayers()) do
		Player:Kick("Error on the server side. Removing players.")
	end
end


game.ReplicatedStorage.promptStartScreen.OnServerEvent:Connect(function()
	game.ReplicatedStorage.isReady.Value = true
	game.ReplicatedStorage.startGame:FireAllClients()
end)

game.ReplicatedStorage.promptPasscode.OnServerEvent:Connect(function(Player, Code)
	if string.upper(Code) == string.upper(Password) then
		game.ReplicatedStorage.loginSuccessful:FireClient(Player)
	else
		Player:Kick("Failed to login.")
	end
end)

game:BindToClose(function()
	connection:Disconnect()
end)

Alright, that now kinda pin points the issue, nothing is being published, either that or something is going wrong with receiving it. Could you paste the stringMessage for me?

Code behind it:

	local sendingTable ={
					Password = FirstThreeLetters..RandomNumber,
					AccessCode = serverCode,
					Difficulty = DataTable.Difficulty,
					Host = Player.UserId

				}
				local stringMessage = sendingTable.Host.." "..sendingTable.Password.." "..sendingTable.Difficulty.." "..sendingTable.AccessCode
				print(stringMessage)
				local publishSuccess, publishResult = pcall(function()
					MessagingService:PublishAsync(MessagingTopic, stringMessage)
				end)

What does stringMessage print out exactly when you run the game?

Uhmm give me a minute to test in roblox player

The reason I asked was because messaging service only allows messages at a maximum file size of 1 kB, which could possibly rule out why you are never receiving what you was meant to publish.

Don’t worry I’m trying to get it rn

Alternatively if this just doesn’t work out for you then maybe you can use a datastore for the sending table and then use messaging service to relay when it is time to grab that info from the datastore.

1 Like

This is a screen shot of the output. The message is the super long string

Strange, only comes back to 78 bytes in size. Have you tried removing the return from the pcall function on the receiving end?

1 Like

No difference, no sign of the connection ever firing

Is subscribeSuccess ever even returning true?

Disregard this. Does the script ever publish before subscribeasync is called?

1 Like