Why isn't playerremoving printing anything?

local players = game:GetService("Players")
players.PlayerAdded:Connect(function(player)
	local d
	local c
	local cA
	wait(1)
	cA = player.CharacterAppearanceLoaded:Connect(function(character)
		
	end)
	c = player.Backpack.ChildAdded:Connect(function(newTool)
		wait(.1)
		print("tool")
	end)
	d = players.PlayerRemoving:Connect(function(player)
		print("player removing #1")
		print(c)
		if c then
			c:Disconnect()
			print('discon')
		end
		print(c)
		if d then
			d:Disconnect()
		end
		if cA then
			cA:Disconnect()
		end
	end)
end)
players.PlayerRemoving:Connect(function(player)
	print("player removing #2")
end)

I’m trying to figure out the setup to disconnect events after the player leaves to make sure there isn’t a memory leak. I came across something weird that seems like it should be common sense. Neither of the “player removing” print at all. What am I overlooking?

I’m pretty sure once an Instance is destroyed (in your case the player) it automatically disconnects all events. So I don’t think you need this type of setup.

2 Likes

I see, but would u have any idea of why “player removing #2” isn’t printing when a player leaves?

It worked for me?

4afe6afc15ae04c99f98205c070cdd40

Edit: Try using something like this instead:

local players = game:GetService("Players")

players.PlayerAdded:Connect(function(player)
	print("player joined")
end)

players.PlayerRemoving:Connect(function(player)
	print("player left")
end)

That was a fault on my end. When I used to test it I used a place I forgot that it was set on teamcreate so it required me to commit the scripts first. Thanks

1 Like