Server System in GUI

Hello developers, can someone help me? I’m trying to make a system server GUI that will allow players to create and join servers in the main menu, and then start the game.

I got the server adding works in the server list, but now how can I make the join button work? How would I make the join button work so that when the player clicks join, he will join the server that he clicked on?

Here is a video that shows an example:

Now, when you click the join button, it will run this script from a local

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local JoinLobbyEvent = ReplicatedStorage.Remotes.JoinLobby

script.Parent.MouseButton1Down:Connect(function()
	JoinLobbyEvent:FireServer(script)
end)

This will make sure that when you click the join button, it will fire to the server for only the button that you clicked, so if there are so many servers, it will join you the only one you clicked.


on the server I have This script handles the server, so when you create a server, it will add it to the list.

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerCreateEvent = ReplicatedStorage.Remotes.CreatedServer
local JoinLobbyEvent = ReplicatedStorage.Remotes.JoinLobby

local createdLobbys = {}

ServerCreateEvent.OnServerEvent:Connect(function(Player, SelectChapter, PlayersAmountStats, PrivacyCheck, PasswordCheck)
	local ServerTemplate = Player.PlayerGui.Things.ServerTemplate:Clone()
	ServerTemplate.Text = Player.Name .. "'s Room | 1/4 Players"

	local Lobby = {}
	Lobby.Players = {Player}
	Lobby.PlayerCount = NumberRange.new(1, PlayersAmountStats)
	Lobby.OwnedBy = Player
	Lobby.Chapter = SelectChapter
	Lobby.PrivacyCheck = PrivacyCheck
	Lobby.Password = PasswordCheck
	Lobby.ServerTemplate = ServerTemplate

	for _, player in ipairs(game.Players:GetPlayers()) do
		ServerTemplate:Clone().Parent = player.PlayerGui.MainMenu["Create/Join"].JoinFrame.ServersList
	end

	table.insert(createdLobbys, Lobby)

	local currentPassword = nil

	local connection = JoinLobbyEvent.OnServerEvent:Connect(function(player, script, password)
		local foundScript = false
		for i,v in ServerTemplate:GetDescendants() do
			if v == script then
				foundScript = true
				break
			end
		end

		if foundScript and (not currentPassword or (currentPassword ~= nil and password == currentPassword)) then
			local RoomFrame = player.PlayerGui.MainMenu["Create/Join"].RoomFrame
			RoomFrame.S1.Text = "Chapter: " .. SelectChapter
			RoomFrame.S2.Text = "Players Amount: " .. PlayersAmountStats
			RoomFrame.S3.Text = "Privacy: " .. PrivacyCheck
			RoomFrame.S4.Text = "Password: " .. PasswordCheck
			player.PlayerGui.MainMenu["Create/Join"].JoinFrame.Visible = false
			RoomFrame.Visible = true
			table.insert(Lobby.Players, player)
		elseif not foundScript then
			-- bad password or exploiter firing the wrong script
		end
	end)

	ServerTemplate.Destroying:Wait() -- wait until server tab is deleted
	connection:Disconnect()

	table.remove(createdLobbys, table.find(createdLobbys, Lobby)) -- removes the lobby variable from createdlobbys    
end)

and also that it was supposed to join you on the server you clicked, but I don’t know what is wrong.

1 Like

What I would do is I would make a reserved server, then teleport the players to that server using the reserved server code. If it’s public then I would teleport the players to the jobId instead

its not teleport its a GUI that is getting set visible

What I would do is make a list party list… So like something like this:

-Managed on the server
local CreatedParties = {
["OfficialPogCat"] = {"Player1", "Player2"},
["Koki0991"] = {"Player3", "Player4"}, 

--OfficialPogCat and Koki0991 being The Hosts of the party, Player 1-4 being people who joined. 
},

That way, when someone clicks the Join Button, They are added in the hosts list, and when someone leaves, they are removed from the hosts list. When you want to teleport the players, you have your list of players in the party ready to go! When someone clicks the join button, on the server you will want to fire that information to the party clients and the host that they joined so they know who is in their party.