Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why does my code glitch out on the second creation of a lobby?

Asked by 4 years ago
Edited 4 years ago

So i am creating a game called Number Quest Ultra which is a game about maths where you create lobbies/games to challenge people. I was testing today when i came across this weird series of problems which makes no sense

Creating a lobby, leaving it and creating another has some freaky behaviour.

The first creation of the lobby is perfectly normal, it creates the lobby, adds me to it and the UI only shows 1 player which is me

Leaving this lobby also works fine, returns to the select lobby screen and removes the lobby.

The second time round seems to have the funny behaviour, this time creating 2 of me on the players list when there should only be 1.

Leaving this does not close the lobby, but instead adds a player to it somehow.

Repeating this just leads to an increase in the player count

Server Side

001local lobbies = {}
002local lobbyid = 0
003local mapmodule = require(game.ReplicatedStorage.MapModule)
004local ds = game:GetService("DataStoreService"):GetDataStore("MapChoice")
005local ts = game:GetService("TeleportService")
006 
007local lobbytemplate = {
008    ["GameType"] = "",
009    ["Owner"] = "",
010    ["Map"] = "",
011    ["LobbyID"] = 0,
012    ["Players"] = {}
013}
014 
015local function ReturnPlayers(owner,players)
View all 161 lines...

Client Side Lobby UI Manager

01local function UpdateList(listdata)
02    for i,v in pairs(script.Parent:GetChildren()) do
03        if v.ClassName == "Frame" then
04            local isavaiable = false
05            for a,b in pairs(listdata) do
06                if b["LobbyID"] == v.ID.Value then
07                    isavaiable = true
08                end
09            end
10            if isavaiable == false then
11                v:Destroy()
12            else
13                for a,b in pairs(listdata) do
14                    if b["LobbyID"] == v.ID.Value then
15                        if b["GameType"] == "Normal" then
View all 55 lines...

Client Side Player List Manager

01local function UpdateList(playerlist)
02    for i,v in pairs(script.Parent:GetChildren()) do
03        if v.Name == "PlayerFrame" then
04            v:Destroy()
05        end
06    end
07    for i,v in pairs(playerlist) do
08        local clone = game.ReplicatedStorage.PlayerFrame:Clone()
09        clone.PlayerName.Text = v
10        clone.Parent = script.Parent
11    end
12end
13 
14game.ReplicatedStorage.UpdatePlayerList.OnClientEvent:Connect(function(playerlist)
15    UpdateList(playerlist)
16end)

I am truly confused and just can't understand why this happens

0
I assume one of your if statements is returning false, perhaps use some print and warn statements to detect if that is the case zomspi 541 — 4y

Answer this question