Player still can join room even though its full and player is not inserted through the tables

So, I’ve made a server system. And im encountering a bug where player still can join them but the server table is full. Is there any fix i can do for this?

if Players.inServer.Value ~= true and v.JoinButton.Text == "JOIN" then
				if tableData[v.JoinButton.Parent.Name].MaxPlayer > #tableData[v.JoinButton.Parent.Name].players then
					print("Player can join this room")
					if not joinDebounce then
						joinDebounce = true
						JoinEvent:FireServer(v.Name)
						v.JoinButton.BackgroundColor3 = Color3.fromRGB(255, 0, 0)
						v.JoinButton.Text = "LEAVE"
						print(Players.Name .. " Joined " .. v.Name)
						Players.inServer.Value = true
						task.wait(.5)
						joinDebounce = false
					end
				end
			end
1 Like

Have you tried printing the values?

Print(maxPlayers, #plrsInTableData)

yeah i did
Lets just say P1 and P2 is inside the room/table and then P3 Wanted to join that duo room
And when P3 Clicked the join button the button changed like the one in code but he is not in the room or table

This script is a bit irritating, but I think I may have found atleast one problem. Your if starts with if Players.inServer.Value ~= true and later you set Players.inServer.Value = true. That means that the whole if will be run 1 time and afterwards always be skipped because Players.inServer.Value is true. Another thing, which isn’t a problem but irritating, why do you set v.JoinButton.Text = "LEAVE", like, what’s this whole joinDebounce do? Did you also maybe misunderstand or even change Players? Because Players normally represents all players but in your case, considering you use Players.Name, it seems like you use it for a single player.

Players is local player.
I added debounce so joining is a bit delayed and prevent some error happening in
v.JoinButton.Leave is so that player can leave the room

Ah ok, very irritating indeed then. Then maybe you have forgotten to add the player to tableData[v.JoinButton.Parent.Name].players as there’s a check if tableData[v.JoinButton.Parent.Name].MaxPlayer > #tableData[v.JoinButton.Parent.Name].players but I can’t see the player being added to that table.

Maybe something to do with the server script?

hmmm not sure about that but i dont see any problem there

could make sense because the JoinRoom event is after the if check. but wont that already check if there’s already 2 player inside it?

You did say that P3 was not inserted to the table after he clicked even tho the button effect activated.

Are you reading the table from a moduleScript by a local script and editing it with a script?

the event is inside server script service and its a normal server script.

So if you never add players or only later, it won’t work. But did you actually mean JoinEvent:FireServer(v.Name)? Because this looks like a client-side script, but if you change variables server-side, even on ModuleScripts, those are not automatically synced.

yeah i called them from a client side script. v.Name will get the name of the Frame

If I understand it right then if you print max players and the total members from the room from both client and server side you’ll know the problem?