What do you want to achieve? For context, I’m making some kind of a backrooms game, which you can invite a certain number of players to enter your party. For example, I’m in the game’s lobby, and I decide to invite three of my friends. When we enter the first “level” of the game, I want to reserve a server for them only, and nobody can enter that server. Now, let’s suppose I went to the second level of the game, but my friends are still in the first level. I would be sent to a reserved server “ID” and not in a server filled with other members of another party. And, consequently, when they go past level 1 and join level 2, they would be sent to the same Server ID I was sent previously, and so on with other stages/levels. Additionally, if a certain member of the party supposedly leaves the game and re-joins, they would also be sent to the same Server ID of the level they stopped at, rather than a random server without the party. In addition, if the player leaves the party, they wouldn’t follow the party’s servers anymore, but another one. Thus, we would need to check if there’s already some sort of a ServerID so we don’t create one equal to another party.
What solutions have you tried so far? I didn’t try any solution, I only thought about possible scenarios and scripting I could do for that. I thought about creating Server IDs for the specific party, and storing them in the DataStore (I’m using ProfileStore, so in this case Profile.Data), with the party members inside the Data. Then, when a player, for example, leaves the game, the game would search for its profile before actually joining the server and search for the specific server ID generated by the game, specific to the party. However, I know it’s not that easy, and I want your thoughts.
So, in short, I want specific members inside a specific party to share the places’ Servers equally, meaning that when they go to another server, they would be a sent to a possibly random generated server, and all the other party members that furthermore join the same place, would be sent to the same server, and so on with other places.
get your specific players in an array (table) right before teleporting them (that’s on you)
create a new teleportOptions instance
local TO = Instance.new("TeleportOptions")
set teleportOptions.ShouldReserveServer to true.
TO.ShouldReserveServer = true
you’re good to go. get the PLACEID (not universeID) of level 1 / 2 / 3 or whatever, then use teleportAsync() and send them away using the player array, placeId, and teleport options!!
local TPS = game:GetService("TeleportService")
TPS:TeleportAsync(YOUR_PLACE_ID, PLAYER_ARRAY, TO) --TO is teleport options, but do whatever you named the variable
MemoryStores are great for this as they allow you to temporarily store data across all servers. It is ideal for when you don’t want data to persist forever. There’s 3 primitive data structures: sorted maps, hash maps and queues. I’ll focus on hashmaps because I believe they’ll fit your use case.
The terms hashmap and dictionary can very often be used interchangeably and for simplicity I’ll do that. Basically, a hashmap stores data in the following way:
{["key"] = "value"}
What you could do is save the user’s ID as a key and a table containing a key ReservedServerId, or directly the ID:
{
[1234] = {
ReservedServerId = 1234
}
}
And then, when they join the game, you initially query the MemoryStore and if the user ID is saved, you teleport them using the ReservedServerId.
Using MemoryStores, you can also set a TTL (Time To Live) for the data to be deleted after a certain period of time, this way, you ensure it doesn’t persist.
I understand now. So, in this case, I would create a hashmap memory store, which is virtually a dictionary, with the “party leader” userID (created when they join the game) with the key being a table with ReservedServerID = UserID. If I’m correct, we use memory store because we are getting players from other servers, right?
But I have a question. If my game includes additional places, is my memory store interacting with them? Because if one of the party members ends up getting to a different place from the rest of the party, how can I ensure that a party member goes to their exact ServerID (which is the party leader ID)?
I think I got it. Is that what it would possibly be?
local MSS = game:GetService("MemoryStoreService")
local TeleS = game:GetService("TeleportService")
local plrs = game:GetService("Players")
local TeleportOptions = Instance.new("TeleportOptions")
local hashMap = MSS:GetHashMap("partyID")
local function onPlayerAdded(plr)
local userID = plr.UserID
local succ, err
local currentMap
succ, err = pcall(function()
currentMap = hashMap:GetAsync(userID)
end)
if not succ then return end
if not currentMap then
succ, err = pcall(function()
return hashMap:UpdateAsync(userID, function()
return {
ReservedServer = TeleS:ReserveServer(138285082707960) -- Maybe we need to reserve server for all places?,
playersParty = ... --PlayersParty system
}
end, 3888000)
end)
if succ then
currentMap = hashMap:GetAsync(userID)
end
end
... -- System ...for party creation
local mapValue = currentMap.value
TeleportOptions.ReservedServerAccessCode = mapValue["ReservedServer"]
TeleS:TeleportAsync(138285082707960, {[mapValue[playersParty]]}, TeleportOptions)
hashMap:RemoveAsync(userID) -- Remove the map of the userID so it creates another when entering a new level
end
plrs.PlayerAdded:Connect(onPlayerAdded)
-- Maybe we could try to make another datastore that stores all reserved servers of the party
EDIT: Question…: is memory store shared across sub-places? Because if it is, everything will become infinitely easier.