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

Help with Code?

Asked by 8 years ago

Okay so here is the code:

chatlog = script.Parent.ChatLog
local chat = {}
game.Players.PlayerAdded:connect(function(player)
    player.Chatted:connect(function(msg)
        chatlog.Value = player.Name..": "..msg
        table.insert(chat, chatlog.Value)
        for i=1,player do print(i) 
        print (chat[i])
        end
    end)
end)

I want it to add the value of chatlog every time function(msg) runs to the table. I believe the problem is the for loop. Thanks.

1
for i = 1, #chat do print(i) XToonLinkX123 580 — 8y
0
For future reference, please make your title relevant to the question inside. RoboFrog 400 — 8y

1 answer

Log in to vote
1
Answered by 8 years ago

Your error is at line 7, I don't know what you're writting 1, player because a player is a userdata and not a number so you can't use it in this loop. your code fix here:

chatlog = script.Parent.ChatLog
local chat = {}
game.Players.PlayerAdded:connect(function(player)
    player.Chatted:connect(function(msg)
        chatlog.Value = player.Name..": "..msg
        table.insert(chat, chatlog.Value)
        for i=1, #chat do
        print(i) 
             print (chat[i])
        end
    end)
end)

And if you want to see all things in the table you simple need to do this:

chatlog = script.Parent.ChatLog
local chat = {}
game.Players.PlayerAdded:connect(function(player)
    player.Chatted:connect(function(msg)
        chatlog.Value = player.Name..": "..msg
        table.insert(chat, chatlog.Value)
        for i, v in pairs(chat) do
             print (i, v)
        end
    end)
end)
0
Okay and is there a way to print out every element in the table? intrance 50 — 8y
0
I edited, yeah XToonLinkX123 580 — 8y
Ad

Answer this question