Script Firing Twice When It's Only Supposed to Fire Once

I want this function to print once a player has chatted and the variable is true.
The problem is that it prints twice, and remote event is fired twice.
I’ve tried adding a debounce, (it didn’t work). I’ve also tried counting the number of messages
the player sends, for example

if #Messages == 2 then

It will work if I type it like this.
(and still do it twice)
If I type it like this,

if #Messages == 1 then

Then it will not work, therefore I concluded that it detects 2 messages at a time, strangely,
and it’s not a debounce issue.
And keep in mind that I’m only chatting once.

Player.Chatted:Connect(function(Message)
	local filter = game.ReplicatedStorage.FilertingFunction:InvokeServer(Message)
	if MicrophoneActive then
		print("Firing")
		REvent:FireServer("NewMessage", filter, Channels[Channel].Frequency, "Default")
	end
end)
1 Like

May we see the output?

My guess without the output is that you are considering this line:

print("Firing")

a print

Yes, I am expecting my output to do this
Firing

But instead, it prints it twice,

One rare possibility is two of the same script exist, can you check?

Please show the output.

What I am saying is that the print command prints “Firing” 2 times because the client prints one and the script that responds to the remote event also prints one. Check the color to the left of the prints, if one is blue and one is green, then my prediction is right.

Try to print on every line:

Player.Chatted:Connect(function(Message)
print("1")
	local filter = game.ReplicatedStorage.FilertingFunction:InvokeServer(Message)
print("2")
	if MicrophoneActive then
		print("Firing")
		REvent:FireServer("NewMessage", filter, Channels[Channel].Frequency, "Default")
	end
end)

Tell me if the prints are still duplicating.

Both of them are blue, and im checking right now

1 Like

image
This is how my output ended up.

1 Like

You might try to check?

local Enabled = true

Player.Chatted:Connect(function(Message)
if Enabled then
Enabled = false
	local filter = game.ReplicatedStorage.FilertingFunction:InvokeServer(Message)
	if MicrophoneActive then
		print("Firing")
		REvent:FireServer("NewMessage", filter, Channels[Channel].Frequency, "Default")
	end
end
wait(2) --When this is going to be enabled again
Enabled = true
end
end)

I think this might work

It still fires twice. I believe now it’s a problem with the chat, because I only chat once and it fires twice.

Here’s a suggestion, delete the script, test it. If it still prints, there are multiple scripts. To find those scripts, just click on the print in the output and you should be led t the script. Ten right click on the script and click, “Show on explorer”.

I tried that, I don’t have multiple scripts. I also checked my code, and I don’t have multiple of the same code. I also clicked both of the prints, and it led me directly back to the same script I am using.

1 Like