I am learning how to make a player lobby system through UI, however I am stuck on this problem that I can’t properly update player count on each existing lobby for all clients. Whenever a player joins a lobby, a remote event is fired and the player gets added to a player count table in the serverscript where of course the lobby creator already is, I connect back in the localscript and with the new table values so I can update the player count for the lobby but it seems that I can’t think of a way to do it correctly. I would greatly appreciate the help and if someone could correct me.
LocalScript
game.ReplicatedStorage.JoinLobbyRemoteEvent:FireServer(player, localplayerusername, username)
print(localplayerusername.." has joined "..username.." lobby")
game.ReplicatedStorage.JoinLobbyRemoteEvent.OnClientEvent:Connect(function(localplayerusername, Playerlist)
local PlayerCount = #Playerlist
CreatedLobbyPlayerCountLabel.Text = PlayerCount.."/4"
end)
Serverscript
game.ReplicatedStorage.JoinLobbyRemoteEvent.OnServerEvent:Connect(function(players, localplayerusername, username)
local Playerlist = {username}
print("event received from the client joining lobby")
table.insert(Playerlist, 2, localplayerusername)
game.ReplicatedStorage.JoinLobbyRemoteEvent:FireAllClients(players, localplayerusername, Playerlist)
end)
Of course this is all part of a much bigger code and if there is some confusion about some of the variables then I will explain them.
Error message : Attempt to get length of a number value.