Lobby System Script not working properly (UNSOLVED)

I am making a lobby system for my game but when one user creates a lobby it will appear in all of the players lobby frame when it should only be the people that are in the party here is a video better explaining it: Roblox Infinite Obby Bug.mp4 - Google Drive

Here is the code:

local InPartyTxt = frame:WaitForChild('InLobbyText')
local lobbySizeTxt = frame:WaitForChild('LobbySizeText')
local privacyTxt = frame:WaitForChild('PrivacyText')
local image_Label = frame:WaitForChild('ScrollingFrame'):WaitForChild('ExampleLeaderFrame'):WaitForChild('ImgCard')
local Username = frame:WaitForChild('ScrollingFrame'):WaitForChild('ExampleLeaderFrame'):WaitForChild('Username')
local leader_Frame = frame:WaitForChild('ScrollingFrame'):WaitForChild('ExampleLeaderFrame')

local exampleFrame = frame:WaitForChild('ScrollingFrame'):WaitForChild('ExamplePlayerFrame')

local loadLobbyInfoEVNT = game:GetService('ReplicatedStorage'):WaitForChild('events'):WaitForChild('BindableEvents'):WaitForChild('LoadLobbyInfo')
local Local_player = game.Players.LocalPlayer
local PlayersInLobbyFolder = game:WaitForChild('Workspace'):WaitForChild('PlayerValues'):WaitForChild('PlayersInLobby')

local PlayersInLobbyTable = {}

local PartyLeader

local Players_Service = game:GetService('Players')

local function checkForOtherPlayers(groupName)
	PlayersInLobbyTable = {}  -- Reset table to avoid duplicates
	for _, i in pairs(PlayersInLobbyFolder:GetChildren()) do
		if i.Value == groupName then
			table.insert(PlayersInLobbyTable, i.Name)  -- Store player names, not group names
		end
	end
end

local function createPlayerCard(playerName)
	local playerCard = exampleFrame:Clone()
	playerCard.Name = playerName
	playerCard.Visible = true

	local player_ID = game.Players:GetUserIdFromNameAsync(playerName)
	local player_Name = game.Players:GetNameFromUserIdAsync(player_ID)
	local thumbType = Enum.ThumbnailType.HeadShot
	local thumbSize = Enum.ThumbnailSize.Size420x420
	local content, isReady = Players_Service:GetUserThumbnailAsync(player_ID, thumbType, thumbSize)

	playerCard.ImgCard.Image = content
	playerCard.ImgCard.Size = UDim2.new(0.177, 0, 1, 0)

	playerCard.Username.Text = player_Name

	playerCard.Parent = frame.ScrollingFrame
end

local function GetLobbyInfo()
	task.wait(1)
	for _, i in pairs(game:WaitForChild('Workspace'):WaitForChild('PlayerValues'):GetChildren()) do
		local isInGroup = i:FindFirstChild('IsInGroup')
		if isInGroup and isInGroup.Value == true then
			local GroupName = i:WaitForChild('WhosGroup')
			checkForOtherPlayers(GroupName.Value)

			if i.Name == Local_player.Name then
				PartyLeader = PlayersInLobbyTable[1]

				if PartyLeader then
					local player_ID = game.Players:GetUserIdFromNameAsync(PartyLeader)
					local player_Name = game.Players:GetNameFromUserIdAsync(player_ID)
					local thumbType = Enum.ThumbnailType.HeadShot
					local thumbSize = Enum.ThumbnailSize.Size420x420
					local content, isReady = Players_Service:GetUserThumbnailAsync(player_ID, thumbType, thumbSize)

					image_Label.Image = content
					image_Label.Size = UDim2.new(0.177, 0, 1, 0)

					Username.Text = player_Name

					leader_Frame.Visible = true
					leader_Frame.Name = player_Name
				end
			end

			-- Create player cards for other party members
			for _, playerName in ipairs(PlayersInLobbyTable) do
				if playerName ~= PartyLeader then
					createPlayerCard(playerName)
				end
			end
		end
	end
end

loadLobbyInfoEVNT.Event:Connect(GetLobbyInfo)

Thanks.

2 Likes

Is this a server script or local script?

1 Like

This is a local script located in Starter Gui.

1 Like

Is there a possibly it is a problem with how the script is accessed. Because nothing in your code looks like it could activate multiple clients because it is only used locally so I am thinking that possibly some other script is calling other clients.

Here is the code for the other scripts

JoinLobbyHandler (Client)

local frame = script.Parent:WaitForChild('JoinOpenGameFrame')
local backBTN = frame:WaitForChild('CloseMenu')
local mainframe = frame.Parent:WaitForChild('MainPlayMenuFrame')
local rep = game:GetService('ReplicatedStorage')

local CreateGameLobbyEvnt = rep:WaitForChild('events'):WaitForChild('RemoteEvents'):WaitForChild('CreateGameLobby')
local createLobbyEvent2 = rep:WaitForChild('events'):WaitForChild('RemoteEvents'):WaitForChild('CreateGameLobby2')
local createGameLobby3 = rep:WaitForChild('events'):WaitForChild('RemoteEvents'):WaitForChild('CreateGameLobby3')

local Scrolling_Frame = frame:WaitForChild('OpenGamesList')

local function closeFrame()
	frame.Visible = false

	for _,i in pairs(mainframe:GetChildren()) do
		if i:IsA("TextButton") then -- makes all the buttons interactable.
			i.Interactable = true
		end
	end
end

backBTN.MouseButton1Click:Connect(closeFrame)

local function createlobbyFunc(playerName, UserID, GameSize, Privacy)
	local PlayerNameExample = frame:WaitForChild('OpenGamesList'):WaitForChild('PlayerNameExample')

	local clone = PlayerNameExample:Clone()
	clone.Name = playerName
	clone.Parent = frame:WaitForChild('OpenGamesList')
	clone.Visible = true
	clone:WaitForChild('UsernameLBL').Text = playerName.." Lobby"
	clone:WaitForChild('PlayerCount').Text = "1/"..GameSize
end

createLobbyEvent2.OnClientEvent:Connect(createlobbyFunc)

local function updVals(plrName, UserID, GameSize, Privacy)
	local path_to_Frame = frame:WaitForChild('OpenGamesList')

	local plrFrame = path_to_Frame:FindFirstChild(plrName)

	print("Updating Vals Request Recieved For Lobby: "..plrName.."'s Lobby!")

	local Game_ownerName = plrFrame:WaitForChild('OwnersName')
	local Game_size = plrFrame:WaitForChild('GameSize')
	local Game_Privacy = plrFrame:WaitForChild('GamePrivacy')

	Game_ownerName.Value = plrName
	Game_size.Value = GameSize
	Game_Privacy.Value = Privacy

	task.wait(1.2)
	frame.Visible = false
	frame.Parent:WaitForChild('MainPlayMenuFrame').Visible = false

	game:GetService('ReplicatedStorage'):WaitForChild('events'):WaitForChild('RemoteEvents'):WaitForChild('CreateGameLobby4'):FireServer(UserID, plrName, "update")

	for _,i in pairs(game:WaitForChild('Workspace'):WaitForChild('PlayerValues'):GetChildren()) do
		if i.Name == plrName then
			i:WaitForChild("IsInGroup").Value = true
			i:WaitForChild('WhosGroup').Value = plrName
		end
	end

	task.wait(2)
	local playerValue = game:GetService('Workspace'):WaitForChild('PlayerValues'):WaitForChild('PlayersInLobby'):FindFirstChild(plrName)
	if playerValue then
		playerValue.Value = plrName
	end
end

createGameLobby3.OnClientEvent:Connect(updVals)

local function JoinParty(User_Who_Joining)
	local PlrName = game.Players.LocalPlayer
	local IsInGroupValFolder = game:WaitForChild('Workspace'):WaitForChild('PlayerValues')
	local value = IsInGroupValFolder:FindFirstChild(PlrName.Name):WaitForChild('IsInGroup')
	
	if not value.Value then
		print("Player not in lobby joining now...")
		game:GetService('ReplicatedStorage'):WaitForChild('events'):WaitForChild('RemoteEvents'):WaitForChild('CreateLobbyVal2'):FireServer(PlrName.Name, "create_Vals")
		game:GetService('ReplicatedStorage'):WaitForChild('events'):WaitForChild('RemoteEvents'):WaitForChild('CreateGameLobby4'):FireServer(PlrName.Name, User_Who_Joining, "update")
	else
		print("you are already in lobby")
	end
end

game:GetService('ReplicatedStorage'):WaitForChild('events'):WaitForChild('BindableEvents'):WaitForChild('JoinParty_Event').Event:Connect(JoinParty)

Create Lobby Handler (Client)

-- Script to handle the "CreateGamesFolder" Frame.

local frame = script.Parent:WaitForChild('CreateGameFrame')
local backBTN = frame:WaitForChild('CloseMenu')
local mainframe = frame.Parent:WaitForChild('MainPlayMenuFrame')
local createButton = frame:WaitForChild('Create')
local errorMessage = frame:WaitForChild('ErrorMessage')
local successMessage = frame:WaitForChild("SuccessMessage")
local textbox = frame:WaitForChild('EnterPlayerAmount')
local lobbyPrivacyText = frame:WaitForChild('LobbyPrivacyLBL')

local privacy_publicBTN = frame:WaitForChild('PublicBTN')
local privacy_privateBTN = frame:WaitForChild('PrivateBTN')
local privacy_value = frame:WaitForChild('LobbyPrivacy')

lobbyPrivacyText.Text = "Party Privacy Not Set Yet!"
lobbyPrivacyText.TextColor3 = Color3.new(1,0,0)

local rep = game:GetService('ReplicatedStorage')

local CreateGameLobbyEvnt = rep:WaitForChild('events'):WaitForChild('RemoteEvents'):WaitForChild('CreateGameLobby')

local function closeFrame()
	privacy_value.Value = ""

	for _,i in pairs(mainframe:GetChildren()) do
		if i:IsA("TextButton") then -- makes all the buttons interactable.
			i.Interactable = true
		end
	end

end

backBTN.MouseButton1Click:Connect(closeFrame)

local function stripNONnumbers() -- Removes text that is not a number from the textbox.
	textbox.Text = textbox.Text:gsub("%D","")
end

textbox:GetPropertyChangedSignal("Text"):Connect(stripNONnumbers) -- Runs the function when text is typed in the textbox

local function update_privacy() -- updates privacy
	
	if privacy_value.Value == "" then
		lobbyPrivacyText.Text = "Party Privacy Not Set Yet!"
		lobbyPrivacyText.TextColor3 = Color3.new(1,0,0)
	end
	
	if privacy_value.Value == "public" then
		lobbyPrivacyText.Text = "Lobby Privacy: Public"
		lobbyPrivacyText.TextColor3 = Color3.new(0, 1, 0)
	elseif privacy_value.Value == "private" then
		lobbyPrivacyText.Text = "Lobby Privacy: Private"
		lobbyPrivacyText.TextColor3 = Color3.new(1, 0, 0)
	end
end

privacy_value.Changed:Connect(update_privacy)

privacy_publicBTN.MouseButton1Click:Connect(function()
	privacy_value.Value = "public"
end)

privacy_privateBTN.MouseButton1Click:Connect(function()
	privacy_value.Value = "private"
end)

local function createGame()
	local playerName = game:GetService('Players').LocalPlayer.Name
	local userID = game:GetService('Players').LocalPlayer.UserId
	local privacy = privacy_value.Value
	local gameSize = textbox.Text
	local mps = game:GetService('MarketplaceService')
	
	if mps:UserOwnsGamePassAsync(userID,814881978) then
		gameSize = 24
	else
		gameSize = 4
	end
	
	CreateGameLobbyEvnt:FireServer(playerName, userID, privacy, gameSize)
	game:GetService('ReplicatedStorage'):WaitForChild('events'):WaitForChild('RemoteEvents'):WaitForChild('CreateLobbyVal2'):FireServer(playerName, "create_Vals")
	closeFrame()
end

createButton.MouseButton1Click:Connect(createGame)

Create Lobby Script (Server)

local rep = game:GetService('ReplicatedStorage')
local createLobbyEvent = rep:WaitForChild('events'):WaitForChild('RemoteEvents'):WaitForChild('CreateGameLobby')
local createLobbyEvent2 = rep:WaitForChild('events'):WaitForChild('RemoteEvents'):WaitForChild('CreateGameLobby2')
local createGameLobby3 = rep:WaitForChild('events'):WaitForChild('RemoteEvents'):WaitForChild('CreateGameLobby3')

local function createlobbyFunc(p, playerName, UserID, Privacy, GameSize)
	playerName = tostring(playerName)
	UserID = UserID
	GameSize = tostring(GameSize)
	Privacy = tostring(Privacy)
	
	print("Lobby Creation Info:")
	print("Name: "..playerName)
	print("UserID: "..UserID)
	print("Lobby Privacy: "..Privacy)
	print("Lobby Size: "..GameSize)
	
	createLobbyEvent2:FireAllClients(playerName, UserID, GameSize, Privacy)
	
	createGameLobby3:FireAllClients(playerName, UserID, GameSize, Privacy)
end

createLobbyEvent.OnServerEvent:Connect(createlobbyFunc)

These are the important scripts which the error might be coming from.

1 Like

In the orignal script you posted I noticed that you loop through all the players in the group outside of where you check if you had the player in the group