:FireClient() is for some reason firing for every client

Been working on this lobby system, and for some reason no matter how hard I try, the leave button appears for all clients I test with.

Basically, when I enter the trigger, it brings up the gui that i want it to bring up, but it enables the Gui for everybody, keep in mind that the remote events are client sided, and it still fires for everybody. If you have a solution to this let me know, because it’s getting annoying lol.

Serverside:

Players = game:GetService("Players")
LobbyJoiner = script.Parent
TeleportService = game:GetService("TeleportService")
TeleportOptions = Instance.new("TeleportOptions")
TeleportOptions.ShouldReserveServer = true
PlayerCount = 0
MaxPlayerCount = 9
PlayerCountGUI = script.Parent.SurfaceGui
LeaveGUI = game.StarterGui.LeaveGUI.Frame
PlayersInQueue = {}

script.Parent.Touched:Connect(function(hit)
	local player = game.Players:GetPlayerFromCharacter(hit.Parent)--If you are editing because of the errors, don't worry the script works. The errors don't really mean much, since again it works well, i have tested with multple players, so don't worry.
	local gui = player.PlayerGui
	
	if hit.Parent:FindFirstChild("Humanoid") and PlayerCount ~= MaxPlayerCount then
		for i, v in pairs(PlayersInQueue) do
			if v == player then
				return
			end
		end
		game.ReplicatedStorage.guiOn:FireClient(player)
		PlayerCount += 1
		table.insert(PlayersInQueue, player)
		print(PlayerCount)
		print(PlayersInQueue)
		script.Parent.SurfaceGui.Frame.TextLabel.Text = PlayerCount .. " / " .. MaxPlayerCount
	end
	
	gui.LeaveGUI.Frame.StoryModeExit1.MouseButton1Down:Connect(function()
		for i, v in pairs(PlayersInQueue) do
			if v == player then
				table.remove(PlayersInQueue, i)
				PlayerCount -= 1
				game.ReplicatedStorage.guiOn:FireClient(player)
				print(PlayerCount)
				print(PlayersInQueue)
				hit.Parent:WaitForChild("HumanoidRootPart").Position = workspace:FindFirstChild("Map").TeleportExits.Elevator1TpExit.Position
				script.Parent.SurfaceGui.Frame.TextLabel.Text = PlayerCount .. " / " .. MaxPlayerCount
			end
		end
	end)
end)

Client Side (Remote Event)

game.ReplicatedStorage.guiOn.OnClientEvent:Connect(function(player)
	game.Players.LocalPlayer.PlayerGui.LeaveGUI.Enabled = true
end)
game.ReplicatedStorage.guiOff.OnClientEvent:Connect(function(player)
	game.Players.LocalPlayer.PlayerGui.LeaveGUI.Enabled = false
end)
2 Likes

ur connecting to MouseButton1Down on each .touched trigger, consider transfering it outside or doing :Once or remotes

This usually happens because you have a server script being duplicated and its firing for each client in response to one client’s query. Or just something of that nature. So my question here, offering help, is where are you storing the server script?

1 Like

Screenshot 2025-07-16 200849
It’s being stored inside a part.

Are there multiples of this part (and thus script) but only one singular remote event?

1 Like

There is one single instance of this part.

I’m pretty sure it’s because of this:

	gui.LeaveGUI.Frame.StoryModeExit1.MouseButton1Down:Connect(function()
		for i, v in pairs(PlayersInQueue) do
			if v == player then
				table.remove(PlayersInQueue, i)
				PlayerCount -= 1
				game.ReplicatedStorage.guiOn:FireClient(player)
				print(PlayerCount)
				print(PlayersInQueue)
				hit.Parent:WaitForChild("HumanoidRootPart").Position = workspace:FindFirstChild("Map").TeleportExits.Elevator1TpExit.Position
				script.Parent.SurfaceGui.Frame.TextLabel.Text = PlayerCount .. " / " .. MaxPlayerCount
			end
		end
	end)

Instead of handling this via server side code, just make it a local script and fire a remote event to leave the queue. You’re making a new connection every time the part is touched; it’s inefficient and it causes issues like the one you’re encountering.

You should use a simpler approach.
For example:

  • Use :SetAttribute() and :GetAttribute() on the Player from the Server.
  • The Client can listen to :GetAttributeChangedSignal() to toggle the LeaveGui.