Can someone help me fix this script?

I know I have made another post about this, but I’ve found a huge flaw in my code. While playtesting, I checked the console. It said that “table.find()” was being misused. How could I fix this?

local Lobbies = {}
local LobbyMembers = {}
game.ReplicatedStorage.RecieveLobbies.OnServerEvent:Connect(function(Player, Action, Action2)
	if Action == "Create" then
			table.insert(Lobbies, Player.Name)
			table.insert(LobbyMembers, {Player})
		game.ReplicatedStorage.RecieveLobbies:FireAllClients(Lobbies, "Create", LobbyMembers)
	end
	if Action == "Disband" then
		for i, Item in pairs(Lobbies) do
			if Item == Player.Name then
				table.remove(Lobbies, table.find(Lobbies, Item))
				table.remove(LobbyMembers, table.find(Lobbies, Item))
				game.ReplicatedStorage.RecieveLobbies:FireAllClients(Lobbies, "Disband", LobbyMembers)
			end
		end
	end
	if Action == "Begin" then
		for i, Item in pairs(Lobbies) do
			if Item == Player.Name then
				local CustomID = game:GetService("TeleportService"):ReserveServer(72909619321737)
				game:GetService("TeleportService"):TeleportToPrivateServer(72909619321737, CustomID, LobbyMembers[table.find(Lobbies, Player.Name)])
				table.remove(Lobbies, table.find(Lobbies, Item))
				table.remove(LobbyMembers, table.find(Lobbies, Item))
				game.ReplicatedStorage.RecieveLobbies:FireAllClients(Lobbies, "Begin", LobbyMembers)
			end
		end
	end
	if Action == "Join" then
		if Player.Name ~= Action2 then
			table.insert(LobbyMembers[table.find(Lobbies, Action2)], Player)
			print(table.find(Lobbies, Action2))
			game.ReplicatedStorage.RecieveLobbies:FireAllClients(Lobbies, "Join", LobbyMembers)
		end
	end
	if Action == "Quit" then
		if Player.Name ~= Action2 then
			for i, Item in pairs(Lobbies) do
				if Item == Action2.Name and table.find(LobbyMembers[table.find(i, Lobbies)], Player.Name) then
					table.remove(LobbyMembers[table.find(i, Lobbies)], table.find(LobbyMembers[table.find(i, Lobbies)], Player.Name))
				end
			end
			game.ReplicatedStorage.RecieveLobbies:FireAllClients(Lobbies, "Quit", LobbyMembers)
		end
	end
end)
game.Players.PlayerRemoving:Connect(function(Player)
	for i, Item in pairs(Lobbies) do
		if Item == Player.Name then
			table.remove(Lobbies, table.find(Lobbies, Item))
			table.remove(LobbyMembers, table.find(Lobbies, Item))
			game.ReplicatedStorage.RecieveLobbies:FireAllClients(Lobbies, "Disband", LobbyMembers)
		end
	end
end)

I’ve not encountered any messages like that over the years. Can you please send a screenshot of the actual message?


Also, at a couple of points in your script, you have

table.remove(Lobbies, table.find(Lobbies, Item))
table.remove(LobbyMembers, table.find(Lobbies, Item))

You either should change the Lobbies thing in the second line to LobbyMembers, or switch the order of the lines, as currently it will result in table.remove receiving the position nil

1 Like

I can’t send any images, due to the hard work required to get a singular one.
Also, I can’t understand what you mean by “switch them around”. Sorry, I’m low on sleep.

switching them around like this:

table.remove(Lobbies, table.find(Lobbies, Item))
table.remove(LobbyMembers, table.find(Lobbies, Item))

table.remove(LobbyMembers, table.find(Lobbies, Item))
table.remove(Lobbies, table.find(Lobbies, Item))

or if you dont want to switch them:

table.remove(Lobbies, table.find(Lobbies, Item))
table.remove(LobbyMembers, table.find(LobbyMembers, Item))
1 Like

Sorry, but it’s still broken. While testing, I found this however.
Screenshot 2025-03-13 201541

That error seems to be seperate, and caused by the following line:

if Item == Action2.Name and table.find(LobbyMembers[table.find(i, Lobbies)], Player.Name) then

I’m not entirely clear what the second part is wanting to do, so I can only suggest that you try rewriting it, as it seems convoluted and broken (hence errors)

1 Like

It’s supposed to kick the player from the lobby, but it doesn’t work.