Hey! A few days ago I had dissected another persons lobby GUI system and am taking a crack at making my own! It has been going pretty smoothly so far but there is a minor hiccup that I have ran into.
Whenever a player joins the lobby, their name gets added as a stringValue to a folder and when the player requests to join by clicking the join button. That specified lobby is searched through and if the players name isn’t found, they are added and if it is found. nothing should happen.
That is in theory how it SHOULD be working but the problem I’m running into is that the button can be clicked multiple times which keeps creating new stringValue instances of the player. This obviously is not what is supposed to be happening. Below I have linked a video demonstrating the problem with the Lobby folder open along with the output.
I do not know what I’m missing because I have looked over my own script a few times and can’t wrap my head around what is happening.
Function that updates all joinable lobbies: (Local Script)
local function lobbyPageUpdate() --Updates the lobby page with all available lobbies.
print("Updating lobby page!")
guiRefresh(masterFrame.LobbyPage.ScrollingLobby)
for _, lobby in pairs(lobbies:GetChildren()) do
if lobby:IsA("Folder") then
local lobbyClone = lobbyPreset:Clone()
local leader = findPlayerType(lobby, "Leader")
lobbyClone.LobbyImage.Image = getAvatar(leader.Name)
lobbyClone.LobbyName.Text = leader.Name.."'s Lobby"
lobbyClone.Parent = masterFrame.LobbyPage.ScrollingLobby
lobbyClone.Join.MouseButton1Click:Connect(function()
--print("Sending request to join "..lobby.Name)
lobbyRemote:FireServer("Join", lobby)
end)
end
end
end
instructions sent to the server where the player and lobby data is caught: (Server Script)
lobbyRemote.OnServerEvent:Connect(function(plr, instruction, data)
if instruction == "Create" then
for _, currentLobbies in pairs(lobbies:GetChildren()) do
if currentLobbies.Name == plr.UserId.."'s Lobby" then
print("Player already created a lobby!")
return
end
end
--print("Creating new lobby")
local newLobby = Instance.new("Folder")
newLobby.Name = plr.UserId.."'s Lobby"
newLobby.Parent = lobbies
local newMember = Instance.new("StringValue")
newMember.Name = plr.Name
newMember.Parent = newLobby
local leader = Instance.new("StringValue")
leader.Name = "Leader"
leader.Parent = newMember
--This is the problem area I believe
elseif instruction == "Join" then
print(plr.Name.." requested to join " ..data.Name) --The player that requested to join and the lobby they are joining.
for _, member in pairs(data:GetChildren()) do
if member.Name == plr.Name then
print("Player is already in this lobby!")
return
else
print("Player is not in this lobby!")
local newMember = Instance.new("StringValue")
newMember.Name = plr.Name
newMember.Parent = data
end
end
end
end)