I am creating a lobby system. Currently, the server will do a scan in a folder to check if you already have a lobby. If you do, it’ll deny the creation of a new lobby.
For some reason, :GetChildren() seems to be returning children even if they have already been deleted. This causes you to be unable to create a lobby if you leave a lobby and then attempt to create one.
Code that creates a lobby:
function CreateLobby(Player, Heist)
local AlreadyExistingLobby = nil
for i, v in pairs(Lobbies:GetChildren()) do --this checks to see if player already has a lobby
local SearchHost = v.Name
if SearchHost == Player.Name then
print("Match found!")
AlreadyExistingLobby = v
end
end
if AlreadyExistingLobby == nil then --if they dont already have a lobby
print(Player.Name .. " is not currently hosting! Proceeding with lobby creation...")
local CurrHeist = Heists[Heist]
local NewLobby = script.SampleLobby:Clone()
NewLobby.Name = Player.Name
NewLobby.Host.Value = Player
NewLobby.MaxPlayers.Value = 4
NewLobby.Map.Value = Heist
NewLobby.Difficulty.Value = "Normal"
NewLobby.Permission.Value = "Public"
NewLobby.Tactic.Value = "Any"
NewLobby.Parent = Lobbies
JoinLobby(Player, Player)
elseif AlreadyExistingLobby ~= nil then --if they already have a lobby, do this
warn(Player.Name .. " failed the confliction test! Sending out error message...")
local Reason = ("You already have an ongoing lobby!")
game.ReplicatedStorage.LobbySystem.Error:FireClient(Player, Reason)
end
end
But as you can see in the code below that removes lobbies, the lobby does indeed get deleted. Even if I check in the folder from the server, it doesn’t show up and yet GetChildren says it exists.
function RemoveLobby(Player)
for i, v in pairs(Lobbies:GetChildren()) do
if v.Name == Player.Name then
v:Destroy()
end
end
end
Any help would be much appreciated!