So,I was making a chat log added event so I can find if a new value has been added to the table named ChatLog but for some reason Line 18 doesn't seem to work when a player chats twice but it works in the first time a player chats.Why and how would I fix it so it can work when a player chats twice?
I'm using the server console in my place to test it out.
ChatLog = {}
--------------------Vairbles----------------------------
NewChatAdded = script.NewChatAdded--Bindable Event
AmountOfChats = 0
------------------Functions-----------------------------
function ChatLogInsert(String)
table.insert(ChatLog,String)
return String
end
----------------------Events----------------------------
game.Players.PlayerAdded:connect(function(Player)---ChatAddedEvent
Player.Chatted:connect(function(Chat)
AmountOfChatsNow = #ChatLog --Kinda like tick()
NewChatAdded.Event:connect(function()
PlayerSaid = ChatLogInsert(Chat)
AmountOfChats = #ChatLog-- now lets record and hopefully see of there should be a diffrence
NumberOfNewChats = math.floor(AmountOfChatsNow - AmountOfChats)--Find the diffrence by subtracting
if NumberOfNewChats > 0 then
print(Player.Name," had said ",PlayerSaid)
else
print(NumberOfNewChats)
end
end)
end)
end)
---------------------------------------------------------
game.Players.PlayerAdded:connect(function(Player)
Player.Chatted:wait()
NewChatAdded:Fire()
end)

2 comments
As a side note:
table.insert(ChatLog,String)is sufficient. The "where to insert" (#ChatLog) is optional, and defaults to the length of the table (#ChatLog).Thanks for the note and I edited the function