Problems with my custom player made server system

  1. What do you want to achieve?
    a custom player made server system that are made by players also the servers are always visable

  2. What is the issue?
    i have no idea how i would make players join the server that shows on the server list that joins the same server that others are in when joining

server script:
currently it handles server creation and deleting them

local dataStoreService = game:GetService("DataStoreService")
local teleportService = game:GetService("TeleportService")

local PlayerMadeServerIdData = dataStoreService:GetDataStore("PLayersServersId")
local ServerIdData = dataStoreService:GetDataStore("ServersId")

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function()
		local screenGui = plr.PlayerGui:WaitForChild("ScreenGui")
		local Server
		local success, data = pcall(function()
			return PlayerMadeServerIdData:GetAsync(plr.UserId)
		end)

		if not success then
			print("unable to load")

			local retry = 0

			while retry < 5 do
				success, data = pcall(function()
					return PlayerMadeServerIdData:GetAsync(plr.UserId)
				end)

				if not success then
					wait(1)
				else
					print("data found ",retry)
					break
				end
			end
		end

		if success then
			if data then
				Server = data
				print("Success")
				for i,v in pairs(Server) do
					local newframe = script.YourServerTemplate:Clone()
					newframe.Parent = screenGui.Frame.PlayerServersFrame
					newframe.NameText.Text = Server[i][1]
					newframe.JoinCode.Text = Server[i][2]
					newframe.Code.Value = Server[i][2]
					print("loaded a server")
				end
			else
				print("new player")
			end
		else
			print("error")
		end	

		--load server list

		local Server
		local success, data = pcall(function()

			return ServerIdData:GetAsync("Servers")
		end)

		if not success then
			print("unable to load")

			local retry = 0

			while retry < 5 do
				success, data = pcall(function()
					return ServerIdData:GetAsync("Servers")
				end)

				if not success then
					wait(1)
				else
					print("data found ",retry)
					break
				end
			end
		end

		if success then
			if data then
				Server = data
				print("Success")
				for _,i in pairs(screenGui.Frame.ServerListFrame:GetChildren()) do
					if i:IsA("Frame") then
						i:Destroy()
					end
				end
				for i,v in pairs(Server) do
					local newframe = script.ServerTemplate:Clone()
					newframe.Parent = screenGui.Frame.ServerListFrame
					newframe.NameText.Text = Server[i][1]
					print("loaded a server")
				end
			else
				print("new player")
			end
		else
			print("error")
		end	
	end)
end)

local function refreshservers()
	for _,i in pairs(game.Players:GetChildren()) do
		local plr = i
		local screenGui = i.PlayerGui.ScreenGui
		local Server
		local success, data = pcall(function()

			return ServerIdData:GetAsync("Servers")
		end)

		if not success then
			print("unable to load")

			local retry = 0

			while retry < 5 do
				success, data = pcall(function()
					return ServerIdData:GetAsync("Servers")
				end)

				if not success then
					wait(1)
				else
					print("data found ",retry)
					break
				end
			end
		end

		if success then
			if data then
				Server = data
				print("Success")
				for _,i in pairs(screenGui.Frame.ServerListFrame:GetChildren()) do
					if i:IsA("Frame") then
						i:Destroy()
					end
				end
				for i,v in pairs(Server) do
					local newframe = script.ServerTemplate:Clone()
					newframe.Parent = screenGui.Frame.ServerListFrame
					newframe.NameText.Text = Server[i][1]
					newframe.Code.Value = Server[i][2]
					newframe.JobId.Value = Server[i][3]
					print("loaded a server")
				end
			else
				print("new player")
			end
		else
			print("error")
		end	
	end
end

game.ReplicatedStorage.CreateServer.OnServerEvent:Connect(function(plr,Text)
	local code
	local save = {}
	local save2 = {}
	if #plr:WaitForChild("PlayerGui").ScreenGui.Frame.PlayerServersFrame:GetChildren() - 1 == 3 then
		print("Max Servers")
	else
		for _,i in pairs(plr:WaitForChild("PlayerGui").ScreenGui.Frame.PlayerServersFrame:GetChildren()) do
			if i:IsA("Frame") then
				table.insert(save,{i.NameText.Text,i.JoinCode.Text})
			end
		end
		code = math.random(111111,999999)
		if  table.find(save,code) then
			print("code in use")
			while table.find(save,code) do
				code = math.random(111111,999999)
				wait(0.1)
			end
		else
			table.insert(save,{Text,code})
		end
		local newframe = script.YourServerTemplate:Clone()
		newframe.Parent = plr.PlayerGui.ScreenGui.Frame.PlayerServersFrame
		newframe.NameText.Text = Text
		newframe.JoinCode.Text = code
		newframe.Code.Value = code
		PlayerMadeServerIdData:SetAsync(plr.UserId, save)
		print("saved data")

		local Server = ServerIdData:GetAsync("Servers")
		if Server then
			for i,v in pairs(Server) do
				local newframe = script.ServerTemplate:Clone()
				newframe.Parent = script.TempServers
				newframe.NameText.Text = Server[i][1]
				newframe.Code.Value = Server[i][2]
				newframe.JobId.Value = Server[i][3]
				print("loaded a server")
			end

			for _,i in pairs(script.TempServers:GetChildren()) do
				if i:IsA("Frame") then
					table.insert(save2,{i.NameText.Text,i.Code.Value,i.JobId.Value})
				end
			end
		end
		table.insert(save2,{Text,code,0})

		script.TempServers:ClearAllChildren()

		ServerIdData:SetAsync("Servers", save)
		refreshservers()
		print("saved data")
	end
end)

game.ReplicatedStorage.DeleteServer.OnServerEvent:Connect(function(plr,frame)
	local NameText = frame.NameText.Text
	local Code = frame.JoinCode.Text
	frame:Destroy()
	local save = {}
	for _,i in pairs(plr:WaitForChild("PlayerGui").ScreenGui.Frame.PlayerServersFrame:GetChildren()) do
		if i:IsA("Frame") then
			table.insert(save,{i.NameText.Text,i.JoinCode.Text})
		end
	end
	PlayerMadeServerIdData:SetAsync(plr.UserId, save)
	print("saved data")
	
	local save2 = {}
	
	local Server = ServerIdData:GetAsync("Servers")
	if Server then
		for i,v in pairs(Server) do
			local newframe = script.ServerTemplate:Clone()
			newframe.Parent = script.TempServers
			newframe.NameText.Text = Server[i][1]
			newframe.Code.Value = Server[i][2]
			newframe.JobId.Value = Server[i][3]
			print("loaded a server")
		end

		for _,i in pairs(script.TempServers:GetChildren()) do
			if i:IsA("Frame") then
				if i.NameText.Text == NameText then
					if i.Code.Value == Code then
						table.insert(save2,{i.NameText.Text,i.Code.Value,i.JobId.Value})
					end
				end
			end
		end
	end

	script.TempServers:ClearAllChildren()

	ServerIdData:SetAsync("Servers", save)
	refreshservers()
	print("saved data")
end)

game.Players.PlayerRemoving:Connect(function(plr)
	local save = {}
	for _,i in pairs(plr:WaitForChild("PlayerGui").ScreenGui.Frame.PlayerServersFrame:GetChildren()) do
		if i:IsA("Frame") then
			table.insert(save,{i.NameText.Text,i.JoinCode.Text})
		end
	end
	PlayerMadeServerIdData:SetAsync(plr.UserId, save)
	print("saved data")
end)

gui:
Screenshot 2023-06-26 094221
Server List:
Screenshot 2023-06-26 094555

  1. What solutions have you tried so far?
    i have tried a bunch of things like jobid but cant figure it out and theres nothing i could find on the fourms
3 Likes

Its been about 10 days and still no response rip if anyone dose come across could u let me know if its normal for this to happen i havent got any progress done because of this

1 Like

Hello! Do you want to make server list?
What PlayerMadeServerIdData contains?
If you want create server for player use TeleportService:ReserveServer()

This function returns an access code that can be used to teleport players to a reserved server, along with the DataModel.PrivateServerId for it.

1 Like

No that works its just telpoting to the correct server so if someone was on test2 and someone else joined it would go into the same server
Sorry its been 6 days i got busy

1 Like

Maybe you need PlayerServerId, not PLayer

1 Like

Everything is working its just idk how to create the system that teleports the player to the corect server
So if a player is already in it it will join that player else start it

1 Like

TeleportToPrivateServer will automatically join an existing server, or else create a new one.

1 Like

I will have a look but i need to figure out how to join the correct one the player clicks on

1 Like