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)