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…
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)
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.
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.