Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Help with If statements?

Asked by 10 years ago

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)
1
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). BlueTaslem 18071 — 10y
0
Thanks for the note and I edited the function kevinnight45 550 — 10y

Answer this question