I’m trying to add a rejoin function to my game so people who get disconnected can rejoin the match they were in. I have a function that adds in the reserve server’s key into their data when they join a match, so they have no problem rejoining the server if they disconnect.
The problem is that if the server does not exist anymore, it will just send them to a new instance of a reserved server. I can’t use MessageService to message to players to see if they’re still in game because the server doesnt exist anymore. Is there any way to detect if a reserved server still exists through the access code without creating a new instance and without MessageService?
You can detect if a reserved server still exists by checking if the key is still valid. You can use the game:GetService("ReplicatedStorage"):FindFirstChild(key) method to check if the key exists in the ReplicatedStorage of the game. If the key exists, it means the server still exists, otherwise, it means the server no longer exists.
Check this code:
local key = "reservedServerKey"
local success, result = pcall(function()
return game:GetService("ReplicatedStorage"):FindFirstChild(key)
end)
if success and result then
-- The reserved server still exists
else
-- The reserved server no longer exists
end
This code tries to find the reserved server key in the ReplicatedStorage using game:GetService("ReplicatedStorage"):FindFirstChild(key) . If it succeeds, it means the reserved server still exists, and you can safely rejoin the server. If it fails, it means the reserved server no longer exists, and you’ll need to join a different server.
I can assume that this response was written by ChatGPT since it is incorrect and is not interpreting “data” correctly.
Furthermore, if ReplicatedStorage’s key does not exist, we cannot know if the server still exists if all players disconnect, because BindToClose fires before all players leave the game.
That’s where MemoryStoreService comes in. I don’t know exactly what you are asking for, but I’m sure you can use this service and add a sorted map to temporarily store data about where the players should go if they disconnect.
@SubtotalAnt8185’s solution is simple and good, although it isn’t proof of a server existing or not, it will get removed after a certain amount of time you decide. You can use this and implement MessagingService so that, if you do not receive any response from the server within X amount of time, you suppose it has closed.
From my tests, it appears that it fires before the last player leaves. There was a test done a while back where someone was very confused as to why this happens.
Auto saving is also a good approach in case the server crashes, as you mentioned.
Why not use MessagingService to send a check to all the servers asking “Are you still there?” and then reply with “Yes, I still am!” while the server that sent the message waits for a reply? You can assume the server is not on if no response is given.