local Players = game:GetService("Players")
local function onCharacterAdded(character)
print(character.Name .. " has spawned")
local function onCharacterRemoving(character)
print(character.Name .. " is despawning")
end
local function UpdateMoney(newBalance)
--money updating
end
local function onPlayerAdded(player)
player.CharacterAdded:Connect(onCharacterAdded)
player.CharacterRemoving:Connect(onCharacterRemoving)
player.Money.Changed:Connect(UpdateMoney)
end
Players.PlayerAdded:Connect(onPlayerAdded)
So if the player leaves, technically the money, charadded and charremoving event still exist and were never disconnected. Does it need to be disconnected and what method would be best to disconnect them?
If the player doesn’t exist anymore then I think it disconnects them automatically, at least it does when you destroy instances so I would think the same applies here
They literally reference destroy in the post, players leaving and instances being destroyed automatically remove all connections:
do -- Also also all good, as Destroy() implicitly disconnects all connections
local p = Instance.new('Part')
p.Touched:connect(function() print(p) end)
p:Destroy()
end
I believe that’s the intended behavior, it’s to allow for yielding code to interact with a disconnected user’s player instance, think game:BindToClose et al.