Disconnecting a function when a player leaves

i THINK i got it but this feels really sloppy
“Players.PlayerAdded:Connect(function(player: Player)
local disconnect = player.Chatted:Connect(function(message: string)
table.insert(chat, message)
end)
while player do
task.wait()
end
disconnect:Disconnect()
end)”
– yes i know it gives the unfiltered message, the code is specifically for analyzing not showing chat, also i don’t know how to filter it :pensive_face:

Connections are automatically disconnected for you when the instance is destroyed, so in the player’s case, any connected event will be disconnected for you

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.