I want to pass the user through a chatted event without anonymous functions.
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..