I was told
1 | game.Players:GetPlayers() |
would work, but I'm trying to use player.Chatted, and it didn't work,
1 | local players = game.Players:GetPlayers() |
2 | players.Chatted:Connect( function (msg) |
3 | print (msg) |
4 | end ) |
I've tried inserting every player into a table, but that didn't work, Thanks for reading this, answers are extremely appreciated :)
We can loop through the players and connect the chatted event to every player.
1 | for Index,Value in pairs (game:GetService( "Players" ):GetPlayers()) do |
2 | value.Chatted:connect( function (msg) |
3 | print (msg) |
4 | end ) |
5 | end |
hydrogyn
EDIT:
the solution to the problem in the comments.
01 | local Players = game:GetService( "Players" ) |
02 | local PlayersInGame = { } -- must contain only objs |
03 |
04 | function UpdateFunction(playerobj) |
05 | playerobj.Chatted:connect( function (msg) |
06 | print (msg) |
07 | end ) |
08 | end |
09 |
10 | function AddPlayerToTable(playerobj) |
11 | table.insert(PlayersInGame,playerobj) |
12 | UpdateFunction(playerobj) |
13 | end |
14 | Players.PlayerAdded:connect(AddPlayerToTable) |
15 |
I tested it and it works. :)
hydrogyn