This isnt really something i need right away but its just for testing purposes/i just wanna mess around with reserved servers, ive heard about “Reserved Servers” and players can access them by using a code… but when i print the code its too long, so i decided to make a custom code that generates… Now how whould i make it so you enter a code in a text box then the player will go to that certain reserved server that has the custom code? How whould i get the reserved server code aka the actual key, that you need to join a reserved server?
You should use MessagingService to handle this, as it allows handling data between servers.
Possible implementation:
Every server has it’s own “shortened ID” (ex. 53A6C) that’s generated at startup.
You could have an event, named something like “GetReservedCode”.
Each server would subscribe to said event, and when someone types in their access code, you fire the event and the corresponding server will message back.
In order to get the actual reserved server code, you can use PrivateServerId.
Sorry but i got the rest of the explanation but what does “each server whould subscribe to said event” mean?
So, i whould generate a code for each server then when a player types the access code for a certain server… it will tp them using the actual reserved server code? But how whould i get the code from the corresponding server? How whould i know what server to check?
Sorry again, quite new to messaging service and reserved servers
So using that func i whould tell the main server (where the player that wants to join is inputting the code) the access code (custom code) and the reserved server code (key code)
How whould i group both of the function? So if the access code matches with the input code ill just have to get the key code from the group?
local MessagingService = game:GetService("MessagingService")
-- When the server starts, generate a random code.
local function GenerateRandomString(length)
local newStr = ""
for _ = 1, length do
newStr ..= string.char(math.random(65, 90)) -- A-Z; see ASCII table
end
return newStr
end
local ServerCode = GenerateRandomString(6)
MessagingService:SubscribeAsync("GetReservedCode", function(message)
local codeReq = message.Data[1] -- The code that the other server wants
local serverIdentifier = message.Data[2] -- So we know where to send the message back
if codeReq == ServerCode then
MessagingService:PublishAsync("ReturnReservedCode", {game.PrivateServerId, serverIdentifier})
end
end)
Each server would also have a unique identifier generated at startup so we can know which message is being sent to which server.
That works!! Thanks a lot!!
I get it now, u type in the code from server1 (the server who wants the other server’s code) will be given to server2 who will take the server’s code request and the actual code checking if they match and if they do, teleport the player… thanks!!!