.Chatted firing twice

Hello, I am currently working on a LocalScript and noticed that the Player.Chatted event fires twice.

I’ve used the .Chatted event a lot of times before and it always fired once, however now it looks like it fires twice. First, it fires with the message being unfiltered (which is how it always was), and then after a small delay it gets fired AGAIN but this time it’s filtered.

I NEED the message to be unfiltered, that’s why I’m using .Chatted. Is this a new Roblox feature, or am I missing something?

This is the script I used to test it:

local Players = game:FindService("Players")

repeat
    task.wait()
until Players.LocalPlayer

local lp = Players.LocalPlayer

lp.Chatted:Connect(function(message)
    print('chatted: ' .. message)
end)

I also modified my script to show what’s being sent in the chat, and this is what i got:

Snímek obrazovky 2023-11-26 v 17.56.51

game.Players.LocalPlayer.Chatted:Connect(function(msg)
    game:GetService("StarterGui"):SetCore("ChatMakeSystemMessage", {
        Text = "[+] Detected: " .. msg,
        Color = Color3.new(0.85, 0.85, 0.85)
    })
end)

Observe how the event fires the unfiltered message first, then SayMessageRequest is fired and it replicates and shows for everyone else in the chat, and THEN the .Chatted event is fired AGAIN but filtered this time. I highly suspect this to be some new unannounced Roblox feature.

Also note that it doesn’t always fire twice, only sometimes. I couldn’t figure out the pattern.

TIA!

Edit: I forgot to clarify that I also need to be able to process the messages from this event very quickly, so debounce is not possible here.

5 Likes

I’m not sure what thee issue is but here is a possible solution I have used in a couple of projects with similar issues:

You could try to create a variable and make ti so that it can only fire if the variable is set to true. Then you could set the variable to false for a short period of time to create a delay to stop it from firing twice.

This is how it could look in code:


local CanChat = true

game.Players.LocalPlayer.Chatted:Connect(function(msg)
if CanChat == true then
    game:GetService("StarterGui"):SetCore("ChatMakeSystemMessage", {
        Text = "[+] Detected: " .. msg,
        Color = Color3.new(0.85, 0.85, 0.85)
    })

 CanChat = false
 wait(.1)
 CanChat = true

end
end)

Hope this helps :slight_smile:

2 Likes

This is a good idea, but I forgot to clarify this in my post: I don’t want to use debounce, because I need to be able to process the messages VERY quickly, at least faster than 50hz.

3 Likes

Do you mean it’s firing lots in a message? Maybe try add wait or debounce

1 Like

No. When you say a message, for example “Hello”, it fires the .Chatted event. Now, it should only fire it once, but it’s being fired twice for some reason. I haven’t made any changes to the script, and it used to work flawlessly before. Also, like I said, there’s no way I’ll be using debounce / wait to overcome this, because I need it to be as fast as possible.

This maybe the cause too

Maybe try

local Players = game:FindService("Players")
local lp = Players:WaitForChild("LocalPlayer")

lp.Chatted:Connect(function(message)
    print('chatted: ' .. message)
end)

Maybe this causes it to work 2 times, because I see no errors there from my view

2 Likes

Idk man, seems like the solution is the debounce, just make it like wait(0.0001) or something, else:

game.Players.LocalPlayer.Chatted:Connect(function(msg)
  wait(0.001)

game:GetService("StarterGui"):SetCore("ChatMakeSystemMessage", {
        Text = "[+] Detected: " .. msg,
        Color = Color3.new(0.85, 0.85, 0.85)
    })

wait(0.001)

end)

try maybe add wait() in the FireServer() line

1 Like

Pretty sure this is because it fires when you send the message, and when the message is received by the server. It behaves like this in TextChatService.

They may have updated the default scripts to take unfiltered messages and pass it through the filter before sending it to all clients. So your script prints the unfiltered, but everyone receives a filtered version, which also fires your chatted event again but with a filtered message.

I can confirm, running into the same issue with admin commands. The event is fired twice “randomly” now, never did that before. I spent days trying to debug why admin commands would only work sometimes and tracked it down to the chat firing twice on random. :roll_eyes:
A debounce is a workaround, we never had to do this before. Why would the same chat event fire twice randomly is not how it worked before. :face_with_raised_eyebrow:

To make it worse, this behavior does not happen in Studio, only in the Client. :neutral_face:

1 Like

I’ll file a bug report, but here is a workaround for it. Adjust to your needs as this is just an example.

-- Local Player Chat Commands
local debounceDelay = false

localPlayer.Chatted:Connect(function(sChatCommand)
	if debounceDelay == true then
		return
	end
	
	debounceDelay = true

	-- Some code that does what you want goes in between
	if string.lower(sChatCommand) == ":cpu" then
		-- Toggle CPU Display Blah Blah
	end

	task.wait(0.5) -- Wait in case of double firing
	debounceDelay = false
end)
2 Likes

Like I said, I need there to be 0 wait. Even a 0.01ms wait would be way too much. I’m still going to mark this as solved for whoever is stuck on this, but afaik there’s currently no method of doing this without debounce.

I agree, my solution is just a band-aid, but I got the attention of the devs here so maybe it can be actually fixed.
https://devforum.roblox.com/t/chatted-randomly-firing-twice-in-public-experiences-only/

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.