Humanoid.Died not firing

When the humanoid dies, this Humanoid.Died Event never fires, even when the player falls into the void.

I’ve looked everywhere and never found a solution.

local DeathEvent = game:GetService("ReplicatedStorage"):WaitForChild("DeathEvent")
local RespawnBind = game:GetService("ReplicatedStorage"):WaitForChild("RespawnBind")
local KillFeedRemote = game.ReplicatedStorage.RemoteEvents:WaitForChild("KillFeed")
local serverModules = game.ServerStorage:WaitForChild("ModuleScripts")
local PlayerStats = require(serverModules:WaitForChild("PlayerStats"))
local Players = game.Players

local connection1

Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(character)
		local Humanoid : Humanoid = character:WaitForChild("Humanoid")
		local HumanoidRootPart : BasePart = character:WaitForChild("HumanoidRootpart")

		local function onDied()
				local CreatorTags = Humanoid:GetChildren()
				DeathEvent:FireClient(plr)

				connection1:Disconnect()

				for i, Tag in ipairs(CreatorTags) do
					if Tag.Name == "creator" then

						local Killer = Tag.Value
						local KillerTickets = Killer:WaitForChild("STATS"):WaitForChild("Tickets")

						if Killer ~= plr then
							local Tickets = math.random(12, 22)
							local Xp = math.random(12, 22)
							KillerTickets.Value += Tickets

							PlayerStats.AddExp(Killer, Xp)

							KillFeedRemote:FireClient(Killer, plr, Tickets, Xp, false)
						end

					elseif Tag.Name == "assist" then

						local assister = Tag.Value
						local assisterTickets = assister:WaitForChild("STATS"):WaitForChild("Tickets")

						if assister ~= plr then
							local Tickets = math.random(7, 12)
							local Xp = math.random(7, 12)
							assisterTickets.Value += Tickets

							PlayerStats.AddExp(assister, Xp)

							KillFeedRemote:FireClient(assister, plr, Tickets, Xp, true)
						end
					end
				end
		end

		connection1 = Humanoid.Died:Connect(function()
			onDied()
			
			print(plr.Name.. "Died.")
			
			connection1:Disconnect()
		end)
	end)
end)

You shouldnt have a global connection1 variable, it would get disconnected for every player if just 1 player dies. You could remove the connection1 entirely and just do Humanoid.Died:Once

If that is not the reason why it doesnt work, try printing the player name after PlayerAdded, same with character after CharacterAdded

3 Likes

Sorry for taking too long to respond.

It seems like its still not working.
When I Reset nothing Happens.

If the Humanoid.Died function is inside another function, then the reason why it could not be working is because of the function containing that.

player.CharacterAdded:Connect(function(character) --This could not be working.
    character.Humanoid.Died:Connect(function()
        -- code
    end)
end)

This is the problem. It is looking for HumanoidRootpart, which is miscapitalized, and thus it will wait forever. I’m surprised you missed it in the output, because it says Infinite yield possible on 'Character:WaitForChild("HumanoidRootpart")'

Either way, your code still looks kinda messy. Just define the function right at the connection, and skip disconnecting it, because it will do that automatically.

Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(character)
		local Humanoid : Humanoid = character:WaitForChild("Humanoid")
		local HumanoidRootPart : BasePart = character:WaitForChild("HumanoidRootPart")

		Humanoid.Died:Connect(function()
			local CreatorTags = Humanoid:GetChildren()
			DeathEvent:FireClient(plr)

			for i, Tag in ipairs(CreatorTags) do
				if Tag.Name == "creator" then

					local Killer = Tag.Value
					local KillerTickets = Killer:WaitForChild("STATS"):WaitForChild("Tickets")

					if Killer ~= plr then
						local Tickets = math.random(12, 22)
						local Xp = math.random(12, 22)
						KillerTickets.Value += Tickets

						PlayerStats.AddExp(Killer, Xp)

						KillFeedRemote:FireClient(Killer, plr, Tickets, Xp, false)
					end

				elseif Tag.Name == "assist" then

					local assister = Tag.Value
					local assisterTickets = assister:WaitForChild("STATS"):WaitForChild("Tickets")

					if assister ~= plr then
						local Tickets = math.random(7, 12)
						local Xp = math.random(7, 12)
						assisterTickets.Value += Tickets

						PlayerStats.AddExp(assister, Xp)

						KillFeedRemote:FireClient(assister, plr, Tickets, Xp, true)
					end
				end
			end
		end)
	end)
end)

I will try this when my wifi goes back on.

Ok, it seems like it’s working properly.
I just need one more thing, how can I check if the player falls into the void?

Also, I didn’t see the Infinite yield possible on ‘Character:WaitForChild(“HumanoidRootpart”)’ because i had Adonis on and it was covering the warning.

You can check where their HumanoidRootPart’s position is located. If it’s under some y, they probably died at some Y position.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.