Humanoid.Died not working

Hey there! So I know there have been a few posts created by this, I can assure you that I went to look at them but none of them have helped. So Basically, I have this script that is supposed to detect who kills who using a died function. However, using prints and testing, I found that the died function doesn’t fire at all. Here is my script:

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(Character)
		if Character:WaitForChild("Humanoid") then
			print("Humanoid found")
			Character.Humanoid.Died:Connect(function()
				print("died")
				if Character.Humanoid:FindFirstChild("Creator") then
					print("Tag found")
					local Killer = game.Players:FindFirstChild(Character.Humanoid.Creator.Value)
					if Killer ~= nil then
						print(Killer.Name)
						if Killer.Team == game:GetService("Teams")["Guards"] then
							if Killer.Policewarn.Value <= 2 then
								game.ReplicatedStorage.Policewarn:FireClient(Killer, Killer.Policewarn.Value)
								Killer.Policewarn.Value = Killer.Policewarn.Value + 1
							else
								game.ReplicatedStorage.Policewarn:FireClient(Killer, Killer.Policewarn.Value)
								Killer.Policewarn.Value = 0
								plr.Character:WaitForChild("Humanoid").Health = 0
								wait(1)
								plr.Team = game:GetService("Teams"):FindFirstChild("Prisoners")
								plr.Isbad.Value = true
							end
						end

					end

				end

			end)
		end
		
	end)
end)

I have tried most things already and there are no errors. The humanoid is found (it prints humanoid found) but when the player dies it doesn’t print “died”. So I am extremely confused on what to do now. Any help would be apprecieated :slight_smile:

Try to setup the humanoid died event on the client and then send a remote event in that event telling the server the player died, and then since your receiving it from the server you can check whoever died and do everything respectively

The reason Humanoid.Died doesn’t fire is because of 2 things:

  • Since scripts are deferred, the script ran late and couldn’t connect up a PlayerAdded event in time to capture a player

  • CharacterAdded event didn’t fire because the character was already added before the event was connected, respawning would solve the problem.

What you want to do is capture current players and call the function for CharacterAdded reliably:

local function PlayerAdded(player)
	local function CharacterAdded(character)
		local humanoid = character:WaitForChild("Humanoid")

		humanoid.Died:Connect(function()
			print("Died")
			if humanoid:FindFirstChild("Creator") then
				print("Tag found")

				local killer = game.Players:FindFirstChild(humanoid.Creator.Value)

				if not killer then
					return
				end

				if killer.Team == game:GetService("Teams").Guards then
					if killer.Policewarn.Value <= 2 then
						game.ReplicatedStorage.Policewarn:FireClient(killer, killer.Policewarn.Value)
						killer.Policewarn.Value += 1
					else
						game.ReplicatedStorage.Policewarn:FireClient(killer, killer.Policewarn.Value)
						killer.Policewarn.Value = 0
						killer.Character:WaitForChild("Humanoid").Health = 0
						wait(1)
						killer.Team = game:GetService("Teams"):FindFirstChild("Prisoners")
						killer.Isbad.Value = true
					end
				end
			end
		end)
	end
	
	CharacterAdded(player.Character or player.CharacterAdded:Wait())
	player.CharacterAdded:Connect(CharacterAdded)
end

game.Players.PlayerAdded:Connect(PlayerAdded)

for _, player in ipairs(game.Players:GetPlayers()) do
	-- the function may yield due to player.CharacterAdded:Wait()
	coroutine.wrap(PlayerAdded)(player)
end

Your code is also bugged, but the issue of Humanoid.Died not firing should be fixed.