PLEASE TELL ME THAT YOU GUYS WOULD RESPOND. THIS IS THE PROBLEM I AM STUCK WITH PLEASE.
Help Information:
I was planning on giving an Idea and help my friend CalypsoGames to achieve it. But we both really had trouble with it. Something like Apeirohobia Lobby System. I know there using ReserveServer() and any functions. I know that, but me and my friend aren’t that advanced yet since were still learning and we just started 3 days ago in Learning Programming.
Pictures (Real Quality if you didn’t understand the Information given):
I do not know how the apeirophobia lobby sytem works but assuming you create a lobby and other people in the server can join then this is how you can achieve what you want.
First of all use a button callback to create a lobby object on the server, use RemoteEvents to tell the server to create a lobby.
-- LocalScript
local createBtn = --path to your gui button
local createEvent = --path to a RemoteEvent
local joinEvent = -- path to a RemoteEvent
local startEvent = --path to a RemoteEvent
local updateGuiEvent = --path to a RemoteEvent
createBtn.MouseButton1Click:Connect(function()
createEvent:FireServer() --this will tell the server to create a local lobby, meaning that the server will just create a record for the lobby
end)
updateGuiEvent.OnClientEvent:Connect(function(lobbyId, action)
if action == "add" then
--create a frame in the gui with a button to join
local button = Instance.new("TextButton")
button.MouseButton1Click:Connect(function()
joinEvent:FireServer(lobbyId)
end)
button.Parent = --frame created above
if lobbyId == game.Players.LocalPlayer.UserId then
--create a button for the owner of the lobby to start the game
--this button should call startEvent:FireServer()
end
elseif action == "remove" then
--remove the frame
end
end)
-- ServerScript
local TeleportService = game:GetService("TeleportService")
local createEvent = -- path to the same event used before
local joinEvent = -- path to the same event used before
local startEvent = --path to the same event used before
local updateGuiEvent = --path to the same event used before
local lobbies = {}
createEvent.OnServerEvent:Connect(function(player) -- player is a default argument which represents the player who fired the event
local userId = player.UserId
if not lobbies[userId] then
lobbies[userId] = {
players = {
userId -- automatically put the owner into the lobby
}
}
updateGuiEvent:FireAllClients(userId, "add") -- tell all clients to show the lobby of the user
end
end)
joinEvent.OnServerEvent:Connect(function(player, userId)
if not userId then
return
end
userId = tonumber(userId) -- since exploits can manipulate scripts and fire events make sure that the argument is a number
if lobbies[userId] and not table.find(lobbies[userId].players, player.UserId) then --make sure that the lobby exists and that the player is not already in it
table.insert(lobbies[userId].players, player.UserId) -- add the player to the lobby
end
end)
startEvent.OnServerEvent:Connect(function(player)
local userId = player.UserId
local lobby = lobbies[userId] -- make a copy of the lobby
if not lobby then
return
end
table.remove(lobbies, table.find(lobbies, lobby)) --delete the lobby so this way if the button is clicked multiple times it won't create more than 1 server
local accessCode = TeleportService:ReserveServer() -- reserve a server and get the access code
TeleportService:TeleportToPrivateServer(0, accessCode, lobbies[userId].players) -- replace 0 with the place id where the actual game is played in, with the last parameter we indicate to the function to teleport ervery player in the lobby
updateGuiEvent:FireAllClients(userId, "remove") -- tell all clients to remove the lobby from the list
end)
Now keep in mind that with this system players can join multiple lobbies so it is your job to understand how to create a system to prevent this based on the code provided. A lobby system is not a simple thing to create if you just started scripting, so i reccomend you to start with basic things first but if you really want to you can work on the base code that i provided above. I also reccomend learning the various methods and functions used to understand what this code does as just copy and pasting is not a good thing and by doing it you will never learn anything.
Thank you so much for the Contribution! I promise to study this as a part of my learning.
Oh and btw. I got alot of red lines.
updateGuiEvent:FireAllClients(userId, "add")
I did the scripts right
-- ServerScript
local TeleportService = game:GetService("TeleportService")
local createEvent = game.ReplicatedStorage.ServerCreation:WaitForChild("createEvent")
local joinEvent = game.ReplicatedStorage.ServerCreation:WaitForChild("joinEvent")
local startEvent = game.ReplicatedStorage.ServerCreation:WaitForChild("startEvent")
local updateGuiEvent = game.ReplicatedStorage.ServerCreation:WaitForChild("updateGuiEvent")
local lobbies = {}
createEvent.OnServerEvent:Connect(function(player) -- player is a default argument which represents the player to fired the event
local userId = player.UserId
if not lobbies[userId] then
lobbies[userId] = {
players = {
userId -- automatically put the owner into the lobby
}
updateGuiEvent:FireAllClients(userId, "add") -- tell all clients to show the lobby of the user
}
end
end)
joinEvent.OnServerEvent:Connect(function(player, userId)
if not userId then
return
end
userId = tonumber(userId) -- since exploits can manipulate scripts and fire events make sure that the argument is a number
if lobbies[userId] and not table.find(lobbies[userId].players, player.UserId) then --make sure that the lobby exists and that the player is not already in it
table.insert(lobbies[userId].players, player.UserId) -- add the player to the lobby
end
end)
startEvent.OnServerEvent:Connect(function(player)
local userId = player.UserId
local lobby = lobbies[userId] -- make a copy of the lobby
if not lobby then
return
end
table.remove(lobbies, table.find(lobbies, lobby)) --delete the lobby so this way if the button is clicked multiple times it won't create more than 1 server
local accessCode = TeleportService:ReserveServer() -- reserve a server and get the access code
TeleportService:TeleportToPrivateServer(0, accessCode, lobbies[userId].players) -- replace 0 with the place id where the actual game is played in, with the last parameter we indicate to the function to teleport ervery player in the lobby
updateGuiEvent:FireAllClients(userId, "remove") -- tell all clients to remove the lobby from the list
end)
Here to
end
elseif action == "remove" then
local createBtn = script.Parent.MainFrame.ServerConfig.ServerCreate
local createEvent = game.ReplicatedStorage.ServerCreation:WaitForChild("createEvent")
local joinEvent = game.ReplicatedStorage.ServerCreation:WaitForChild("joinEvent")
local startEvent = game.ReplicatedStorage.ServerCreation:WaitForChild("startEvent")
local updateGuiEvent = game.ReplicatedStorage.ServerCreation:WaitForChild("updateGuiEvent")
createBtn.MouseButton1Click:Connect(function()
createEvent:FireServer() --this will tell the server to create a local lobby, meaning that the server will just create a record for the lobby
end)
updateGuiEvent.OnClientEvent:Connect(function(lobbyId, action)
if action == "add" then
--create a frame in the gui with a button to join
local button = Instance.new("TextButton")
button.MouseButton1Click:Connect(function()
joinEvent:FireServer(lobbyId)
end)
button.Parent = --frame created above
if lobbyId == game.Players.LocalPlayer.UserId then
--create a button for the owner of the lobby to start the game
--this button should call startEvent:FireServer()
end
elseif action == "remove" then
--remove the frame
end
end)```
Oh yea sorry I wrote it on mobile and I made a few mistakes, the problem was that the line of code that fires all the clients was inside a table. I edited my post, it should work now.
I edited the script. I just don’t know how to do this one
elseif action == "remove" then
--remove the frame
end
end)
Here is my edited code:
-- LocalScript
local createBtn = script.Parent.MainFrame.ServerConfig.ServerCreate
local createEvent = game.ReplicatedStorage.CreationToServer.createEvent
local joinEvent = game.ReplicatedStorage.CreationToServer.joinEvent
local startEvent = game.ReplicatedStorage.CreationToServer.startEvent
local updateGuiEvent = game.ReplicatedStorage.CreationToServer.updateGuiEvent
createBtn.MouseButton1Click:Connect(function()
createEvent:FireServer() --this will tell the server to create a local lobby, meaning that the server will just create a record for the lobby
end)
updateGuiEvent.OnClientEvent:Connect(function(lobbyId, action)
if action == "add" then
--create a frame in the gui with a button to join
local button = Instance.new("TextButton")
button.MouseButton1Click:Connect(function()
joinEvent:FireServer(lobbyId)
end)
button.Parent = --frame created above
if lobbyId == game.Players.LocalPlayer.UserId then
game.StarterGui.Lobby.MainFrame.ServerFire.ServerStart.MouseButton1Click:Connect(function()
startEvent:FireServer()
end)
elseif action == "remove" then
--remove the frame
end
end)```
updateGuiEvent.OnClientEvent:Connect(function(lobbyId, action)
if action == "add" then
--create a frame in the gui with a button to join
local button = Instance.new("TextButton")
button.MouseButton1Click:Connect(function()
joinEvent:FireServer(lobbyId)
end)
button.Parent = --frame created above
if lobbyId == game.Players.LocalPlayer.UserId then
game.Players.LocalPlayer.PlayerGui.Lobby.MainFrame.ServerFire.ServerStart.MouseButton1Click:Connect(function()
startEvent:FireServer()
end)
elseif action == "remove" then
--remove the frame
end
end
end)
By the way you must frame in starter gui as if you do it won’t work, I edited it