Help with .ChildRemoved

Hello,
The script I am working on is supposed print a message when a specific instance named ‘isPlaying’ is removed. However, the script does not seem to function.
(Note: The Instance is removed when the Humanoid dies)

game.Players.PlayerAdded:Connect(function(player)
			player.ChildRemoved:Connect(function()
				wait(1)
				local isPlaying = player:FindFirstChild("isPlaying")
				if isPlaying == nil then
					print("Player is not playing")
				end
			end)
end)

Any help is greatly appreciated!

If you want to detect the humanoid dying why not just use Character Removed

2 Likes

are you removing the instance with a local script? if so then the change will not be replicated to the server and this script will still see the instance as being there

You could just grab the child that was removed by doing Child removed:Connect(function(instance) and then check the name of that instance, that way you can see that the is playing object was removed

Read more about it here Instance | Roblox Creator Documentation

1 Like

I would listen through AncestryChanged on the child objects parent.

local isPlaying = player:FindFirstChild("isPlaying")
if isPlaying then
	isPlaying.AncestryChanged:Connect(function(_, parent)
		if not parent then
			print("Player is not playing")
		end
	end)
end

Or listen to the humanoid

humanoid.Died:Connect(function()
	print("Player died and is not playing")
end)