Chatted function being activated multiple times. how do I disconnect the extras?

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I want only one instance of chatted listening at a time, when I press multiple times, previous instances should be disconnected.
  2. What is the issue? Include screenshots / videos if possible!
    I am making a radio. When I press T multiple times, multiple instances of player.Chatted are created. How do I disconnect those instances when I turn the radio off without saying anything?
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I’ve looked through like, 2 pages of the dev hub using multiple keywords. A few kinda matched my issues but they weren’t replied to.
    After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
local function Listen(player,RadioStatus)
	local chatting 
	chatting = player.Chatted:Connect(function(msg)
		if RadioStatus == 1 then
			UpdateForAllPlayers(msg)
			SendToOverwatch(player,msg)
			StartRec:FireClient(player)
			chatting:Disconnect()
		end
	end)
end

StartRec.OnServerEvent:Connect(Listen)

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

It’s creating a new event every time when it got signal

Not 100% sure

Can any of those functions you are calling in the .Chatted event yield (and possibly yield forever)?

That bit sends a signal back to the client to turn off the radio from listening when something has been said. It connects to this bit in the local script

StartRec.OnClientEvent:Connect(function()

RadioStatus = 0

PGui:WaitForChild("RadioGui").RadioEnd:Play()

I haven’t gotten any yield forever errors so I assume not

You can try adding a print right before the :Disconnect() line to see if it goes to the disconnecting part

Like I said here, that disconnect only activates when something IS said. It disconnects it then. But when I turn it on and off multiple times without saying anything, then I say something,it prints multiple times cause multiple chatted events are listening. How do I destroy those previous chatted events?

Oh, sorry. I misunderstood the issue, you should make it so you check if it’s already listening on the server

local listeningTo = {}

local function Listen(player,RadioStatus)
	if not table.find(listeningTo, player) then
		table.insert(listeningTo, player)
		local chatting 
		chatting = player.Chatted:Connect(function(msg)
			if RadioStatus == 1 then
				UpdateForAllPlayers(msg)
				SendToOverwatch(player,msg)
				StartRec:FireClient(player)
				table.remove(listeningTo, table.find(listeningTo, player))
				chatting:Disconnect()
			end
		end)
	end
end

StartRec.OnServerEvent:Connect(Listen)

What I did here is I added a check to see if the server is already listening to the player, so it doesn’t start more and more events everytime the RemoteEvent is fired

Thanks, I’ll try that.

UPDATE: Fixed, marking as solution, thanks!