I was told
game.Players:GetPlayers()
would work, but I'm trying to use player.Chatted, and it didn't work,
local players = game.Players:GetPlayers() players.Chatted:Connect(function(msg) print(msg) 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.
for Index,Value in pairs(game:GetService("Players"):GetPlayers()) do value.Chatted:connect(function(msg) print(msg) end) end
hydrogyn
EDIT:
the solution to the problem in the comments.
local Players = game:GetService("Players") local PlayersInGame = {} -- must contain only objs function UpdateFunction(playerobj) playerobj.Chatted:connect(function(msg) print(msg) end) end function AddPlayerToTable(playerobj) table.insert(PlayersInGame,playerobj) UpdateFunction(playerobj) end Players.PlayerAdded:connect(AddPlayerToTable) function RemovePlayerFromTable(playerobj) local I = table.find(PlayersInGame,playerobj) table.remove(PlayersInGame,I) UpdateFunction(playerobj) end Players.PlayerRemoving:connect(RemovePlayerFromTable)
I tested it and it works. :)
hydrogyn