I want to pass the user through a chatted event without anonymous functions.
✓ ANSWER ACCEPTED
How can I pass additional arguments through :connect?
2 answers
✓ Accepted answer
If you define the function to be used for the Chatted event inside of the function to be used for the PlayerAdded event, the parameter for the Player will be inherited into the Chatted function.
function add(p) --function for PlayerAdded
local function whenChat(m) --function for Chatted
print(p.Name.." chatted: "..m); --'p' variable inherited
end
p.Chatted:Connect(whenChat) --connection for Chatted
end
game.Players.PlayerAdded:Connect(add)
Although, I do suggest simply using anonymous functions because - one, the code above is defining the function for the Chatted event every time a player joins. And two, you won't need to worry about networking your variables.
game.Players.PlayerAdded:Connect(function(plr)
plr.Chatted:Connect(function(msg)
print(plr.Name.." chatted: "..msg);
end)
end)
It depends on what the script is, you cant put connect in random places..
This discussion is preserved as it was. New answers, comments, and votes are closed.

4 comments
this is cleanest with anonymous functions, i.e., game.Players.PlayerAdded:connect(function(p) p.Chatted:connect(function(msg) end) end)
Minor: you say "the code above defines the function...every time a player joins", but you're doing that anyway on line 2 (in your 2nd script block) -- it is "remade" every time with a new "plr" in its scope.
The new event connection is being defined, yes. But the function is constant in the second code :)
Whereas in the first code, the function would have to be defined when the player is added.