Hello, I’m trying to make a script where someone can join a reserved server (The reserved server is a place by the way), the problem I’m having is that I can’t access the reserved server code. I’m also using cross messaging for this by the way
Does anyone have a solution for this? I’m really stuck here
When you use TeleportService and use TeleportService:ReserveServer it returns the code needed to be able to join reserved servers. If you’re on a ReservedServer server, you can use game.PrivateServerId to get the ReservedServer code (check if it’s not a string or <= 0.)
game.PrivateServerId and ReservedServerAccessCode are not the same. If you try teleporting to a reserved server with game.PrivateServerId, you will get a restricted access error.
The only way to get ReservedServerAccessCode is through the return given by ReserveServer or TeleportAsync with “ShouldReserveServer” set to true in teleport options.
In other words, you can’t get a reserved server “ReserverServerAccessCode” from the same reserved server itself.
For my game, what I did was wherever “:ReserveServer” is used, I store the returned access code and private server ID (:ReserveServer does return 2 variables, not just 1). I then save the private server ID as a key, with the data being the ReservedServerAccessCode. This is because all reserved servers have access to the PrivateServerId, however, the ReservedServerAccessCode can only be obtained through the “:ReserveServer” method. My guess is that Roblox did this for security reasons (which is fair).
To get the access code from the reserved server, you just need to get the data via the key, which is game.PrivateServerId. This should then return the ReservedServerAccessCode.
As for how to save the key and data, you can either use DataStore, MessagingService or MemoryStore. Using MessagingService may be a bit odd to use to get this to work, so I would suggest using MemoryStore instead.