messagingService:PublishAsync() does not work with game:BindToClose()

i have a simple script that sends messages to other servers, i plan on making a server list board that shows a list of all running servers with the option to join them so using messaging service seems like a good idea to send info like player count

For some reason when game:BindToClose() fires it never sends a message to other servers saying that this server is no longer running and i dont know why.

local messagingService = game:GetService("MessagingService")

task.wait(5) -- wait for the server to fully load in

messagingService:SubscribeAsync("ServerList",function(message)
	print(message.Data.JobID)
	print(message.Data.ShutDown)
end)

messagingService:PublishAsync("ServerList",{
    ["JobID"] = game.JobId,
    ["ShutDown"] = false
})

game:BindToClose(function())
    messagingService:PublishAsync("ServerList",{
        ["JobID"] = game.JobId,
        ["ShutDown"] = true
    })
    print("here") -- this gets printed but it never sends message??
    task.wait(5) -- make sure it has enough time to send
end)

Ive tested with an alt with private servers and i can confirm that it sends messages normally except for when the server shuts down, please help ive all ready wasted like 2 days making the ui and everything just for this to not even work xd

FYI : i need to send a message when the server shuts down so that other servers can delete its info and not show players a dead server, i dont want to use a while loop to check if a server hasnt sent a message in a while because that seems inefficient

1 Like

Still having issues even when trying to remake the script and trying in a different game, would be great if anybody could help!

I ended up only using messagingService:PublishAsync() only if the game has 2 or more players,

Instead of game:BindToClose() i used game.Players.PlayerRemoving and checked if # game.Players:GetPlayers() <= 2, if true then send message to servers saying the server is no longer alive (even if it has 1 player, cause for some reason if the last player leaves it wont send a message)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.