Hello. Im wondering when I should disconnect functions.
For example, im making a custom leaderboard, this code will run everytime the player clicks the refresh button:
for _, child in MembersInfoFrame:GetChildren() do
if child.Name ~= 'UIListLayout' then
child:Destroy()
end
end
for _, Player in Players:GetPlayers() do
local TemplateClone = UIListLayout.Template:Clone()
TemplateClone.Text = Player.Name
TemplateClone.Parent = MembersInfoFrame
--etc
TemplateClone.MouseButton1Click:Connect(function() --Checking if the player clicks the the button
end)
end
So the button will be getting destroyed every time the player clicks the refresh button, should I be disconnecting the function when the button(s) are destroyed? If so, how would I do it?