Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Help with Code?

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.

2 comments

1

for i = 1, #chat do print(i)

0

For future reference, please make your title relevant to the question inside.

1 answer

✓ Accepted answer

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)

2 comments

0

Okay and is there a way to print out every element in the table?

0

I edited, yeah

This discussion is preserved as it was. New answers, comments, and votes are closed.