Greetings,
I have a couple of questions and issues regarding this function while in the making of a Private Server System. Here are my questions and issues:
How do I reserve the server that the host makes?
How do I attach the name that the host has given to the reserved server?
How do I attach the code that I generated to the reserved server so other players can connect?
How do I make players connect if they write the correct code?
Thank you!
I have already seen that article. Didn’t really help. I am looking for code examples for my questions that are listed in the post description.
Here’s a small code example I tired to make pretty self explanatory!
-- Services
local Players = game:GetService("Players")
local TeleportService = game:GetService("TeleportService")
-- Tables
local access_code_dictionary = {};
-- Values
local Place_Id = 0
-- Functions
local function ReserveServerForPlayer(player)
local Access_Code = TeleportService:ReserveServer(Place_Id) -- The access code for the server
access_code_dictionary[player] = Access_Code -- Stores the access code with the player object as the index
end
local function TeleportPlayers(host, players) -- host being the player
local Access_Code = access_code_dictionary[host] -- Get the access code
TeleportService:TeleportToPrivateServer(Place_Id, Access_Code, players) -- teleport the players all together
end
Warning tho!
You’ll probably want to store the codes in a datastore instead of a random dictionary lol
The example above is just meant to give you an idea on how they work
The first code example should answer your first 2 and maybe even 3 or 4 questions
The code example below is an example of functions that could be used to teleport the player if they gave the server a code
-- Services
local Players = game:GetService("Players")
local TeleportService = game:GetService("TeleportService")
-- Tables
local access_code_dictionary = {}; -- You probably want this to be in a datastore
-- Values
local Place_Id = 0
-- Functions
local function CodeExists(Access_Code_Given_By_Client)
for player, Access_Code in pairs(access_code_dictionary) do
if Access_Code_Given_By_Client == Access_Code then -- Compare codes in the dictionary
return true; -- If we find a code, return true
end
end
return false; -- If we don't find a code, return false
end
local function TeleportPlayerByCode(player, Access_Code_Given_By_Client)
if CodeExists(Access_Code_Given_By_Client) then -- Check if the code exists
TeleportService:TeleportToPrivateServer(Place_Id, Access_Code_Given_By_Client, {player}) -- Teleport the one player if they gave a valid code
end
end
These are just some examples tho and they don’t cover remote events or datastores — they’re also just from my current understanding of the TeleportService
My apologies if this post has any typos or errors, it’s meant to inform not be copy and pasted, I also didn’t proof read it
1 Like
Thanks a lot, I’ll look into it! Is it possible to contact you in case I have any questions or issues? Thank you once again!
You should be able to message me if you go to my profile, I’m pretty busy but I’d be more than happy to help when I can!
1 Like