So, I have this server list, but it doesn’t update when the server closes. I have tried sending messages when the server closes, but that’s not always a guarantee with MessagingService, so it pretty much never receives the message saying that the server will close. So, my question is, how should I handle removing the server from the Server List when I don’t receive a message from that server?
Currently, I send a message with a parameter “open” to tell whether the server is open or closing. I never am able to receive the last message sent by the destination server saying that the server is closing. And nothing happens within the SubscribeAsync after the server has closed, as no messages are being sent to the topic.
Here’s what I have so far.
Receiver:
ms:SubscribeAsync("ServerList", function(data)
data = data.Data
if data.serverId ~= game.JobId then
-- if the server is still open
if data.open == true then
local serverValue = script.ServerName:Clone()
-- add the server to ReplicatedStorage.Servers
serverValue.Value = data.serverId .. " " .. data.players
serverValue.Parent = serversFolder
serverValue.ServerSize.Value = data.serverSize
wait(5)
serverValue:Destroy()
-- if the server is closing
elseif data.open == false then
-- Delete the server from ReplicatedStorage.Servers
for i,v in pairs(serversFolder:GetChildren()) do
if v.Value == data.serverId then
v:Destroy()
end
end
end
end
end)
Sender:
local ms = game:GetService("MessagingService")
while game.VIPServerId == "" do
local data = {
serverId = game.JobId,
players = #game.Players:GetPlayers(),
serverSize = game.Players.MaxPlayers,
open = true
}
-- send the message to the ServerList topic
ms:PublishAsync("ServerList", data)
wait(5)
end
game:BindToClose(function()
local data = {
serverId = game.JobId,
players = #game.Players:GetPlayers(),
serverSize = game.Players.MaxPlayers,
open = false
}
-- send the message to the ServerList topic
ms:PublishAsync("ServerList", data)
end)