So I’ve decided I want to create a main menu for my game and allow for players to join different kind of sessions (such as solo, roleplay based or public)
My code:
local DatastoreService = game:GetService('DataStoreService')
local ServersDatastore = DatastoreService:GetDataStore('Servers')
function TeleportToDedicatedSession(Player, Type, Id)
local message = Instance.new('Message', workspace)
message.Text = "Teleporting"
repeat wait(1)
local success, err = pcall(function()
local players = {Player}
return TeleportService:TeleportToPrivateServer(OttawaId, Id, players)
end)
until success or not Player
end
function CreateNewSessionAndTeleport(Player, Type)
local code = TeleportService:ReserveServer(OttawaId)
local message = Instance.new('Message', workspace)
message.Text = "Teleporting"
repeat wait(1)
local success, err = pcall(function()
local players = {Player}
return TeleportService:TeleportToPrivateServer(OttawaId, code, players)
end)
until success or not Player
local serverDetails = {id = code, host = Player.UserId, type = Type}
ServersDatastore:SetAsync(code, serverDetails)
end
My main questions are:
-
When I create a new session and all the players leave, how do I check the number of players that are in that server? (without creating place to place communication and doing it in the one script I’m currently writing in)
-
How can I loop through all active sessions that I’ve saved to a datastore?
I’m really curious as to what I can do here, any advice would be perfect. Sorry if the thread sounded a bit bonkers got a bit confused halfway writing it.
Thanks
EDIT:
For an example of what I’m attempting to achieve: