player.Chatted firing twice

So there is this weird thing happening, my script looks like this:

Player.Chatted:connect(function(Message)
	print("CHATTED!")
--ignore rest of code....
	end	
end)

I expect the output to just say “CHATTED” one time. However, it says it 2 times. I have already made sure that this is the only script running and there is nothing else in the function that will print. I am really confused…

1 Like

Oh, hey. Try using a debounce?

Yes, I have and it still does the same thing.

local debounce = false

Player.Chatted:connect(function(Message)
	if debounce then
		return
	end
	debounce = true
	print("CHATTED!")
	--ignore rest of code....
	task.wait(1)
	debounce = false
end)

What about this?

It still fires twice:

That’s weird, are you sure you don’t have the same script copied in 2 different locations?

Press CTRL + SHIFT + F and use the global script search to search for “chatted”.

I already made sure of that:

I tried looking around the forum for others who’ve encountered similar issues but this is a first it seems.

I managed to find this one: Script Firing Twice When It's Only Supposed to Fire Once

Thanks for linking, I’ll take a quick look.

So the lines that I originally mentioned were in a bigger script with a bunch of other functions. So I just tried to put the lines I mentioned above into a new local script with no other lines of code and the output was normal.

I’m guessing not but do you have any custom chat systems in place?

No, only a small system for roblox buble chat, I destroyed that tho and used roblox’s normal system and the same thing happend.

If you had the “Chatted” event in a loop before (which ran twice) then the connected function would execute twice as well. In other words you’d be connecting 2 separate closures (functions) to the “Chatted” event, which when fired would result in both functions being executed.

for i = 1, 2 do
	player.Chatted:Connect(function(msg)
		print(msg)
	end)
end

This is what I’m trying to refer to. Obviously it won’t be that obvious in your script (but I can only assume this is likely what is occurring).

1 Like

Can I see the definition for “Message”?

I think its built into the function, right?

Oh, you’ve collapse the function, can you expand it by clicking the arrow?

Also “:connect()” is deprecated (not necessarily the issue) but “:Connect()” should be used.