Enemy won't died at health 0

I’m making td game while i’m testing for a few times i noticed something
There’s was Mystery Enemy Name “Random Error 2” won’t died at health 0

It’s doesn’t happened every times

Screenshot 2024-04-17 072859

Can your enemies take non integer values of damage ? Like 0.1 damage or something. Maybe in this screenshot, his actual health is 0.4, but your healthbar shows 0 because it is rounded.

1 Like

No? I think so. My tower damage use int value

is Humanoid:SetStateEnabled(“Dead”,false) anywhere in your code? this disables death.

2 Likes

No, I never used Humanoid:SetStateEnabled(“Dead”,false) it before

Then i have absolutely no idea what could prevent a Humanoid’s death.

2 Likes

Here’s the script that inside Random Error 2

local hum = script.Parent.Humanoid

local mob = {"Internet destoryer","Molten","Slime","Hidden Upgraded Error","Blue Screen","Data Transmitter"}

hum.HealthChanged:Connect(function(newhealth)
	if newhealth <= 0 then
		local random = mob[math.random(1,#mob)]
		game.ReplicatedStorage.Events.Mystery:Fire(random,1,workspace.Map:FindFirstChildOfClass("Folder"),script.Parent)
	end
end)

in theory you could call :BreakJoints() to kill any humanoid.

idk if you call it on the model or the humanoid tho, probably the model.

1 Like

Well…


Here my Mob Module

It’s should be something wrong here maybe

local ServerStorage = game:GetService("ServerStorage")
local PhysicsService = game:GetService("PhysicsService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local BossEvent = ReplicatedStorage.Events:WaitForChild("BossEvent")

local events = ReplicatedStorage.Events
local Particle = ReplicatedStorage.Particle
local dpartiele = events.DeadParticle
local TakeDamage = events.TakeDamage
local mob = {}

function MoveNPC(Point, Character)
	local HRP = Character.HumanoidRootPart
	repeat
		task.wait()
		if Character:FindFirstChild("Humanoid") and Character:FindFirstChild("Humanoid").Health > 0 then
			Character.Humanoid:MoveTo(Point)
		else
			break
		end
	until (HRP.Position - Vector3.new(Point.X, HRP.Position.Y, Point.Z) ).magnitude <= 1 or not Character:FindFirstChild("Humanoid")
end

function mob.Move(mob, map)
	local humanoid = mob:WaitForChild("Humanoid")
	local waypoints = map.Waypoints

	for waypoint=1, #waypoints:GetChildren() do
		if mob and mob.Parent then
			mob.MovingTo.Value = waypoint
			MoveNPC(waypoints[waypoint].Position,mob)
		else
			return
		end
		--humanoid:MoveTo(waypoints[waypoint].Position)
		--humanoid.MoveToFinished:Wait()
	end
	
	if mob and mob.Parent then
		if mob.MovingTo.Value == #waypoints:GetChildren() and mob.Humanoid.Health > 0 then
			mob:Destroy()

			map.Base.Humanoid:TakeDamage(humanoid.Health)
			TakeDamage:FireAllClients()
		end
	end
end

function mob.RandomMove(mob,mystery,map)
	local humanoid = mob:WaitForChild("Humanoid")
	local waypoints = map.Waypoints

	for waypoint=mystery.MovingTo.Value, #waypoints:GetChildren() do
		if mob and mob.Parent then
			mob.MovingTo.Value = waypoint
			MoveNPC(waypoints[waypoint].Position,mob)
		else
			return
		end
	end

	if mob and mob.Parent then
		if mob.MovingTo.Value == #waypoints:GetChildren() and mob.Humanoid.Health > 0 then
			mob:Destroy()

			map.Base.Humanoid:TakeDamage(humanoid.Health)
			TakeDamage:FireAllClients()
		end
	end
end

function mob.Spawn(name, quantity, map,old)
	local mobExists = ServerStorage.Mobs:FindFirstChild(name)
	local newboss = nil
	
	if mobExists then
		for i=1, quantity do
			if old then
				if mobExists.Config:FindFirstChild("Summoned") then
					task.wait(.4)
				end
			else
				task.wait(.3)
			end
			
			local newMob = mobExists:Clone()
			
			local height

			if newMob:FindFirstChild("Head") and newMob:FindFirstChild("Left Leg") then
				height = (newMob.PrimaryPart.Size.Y / 2) + newMob["Left Leg"].Size.Y
			else
				height = (newMob.PrimaryPart.Size.Y / 2) + newMob.Humanoid.HipHeight
			end

			local offset = CFrame.new(0, height / 2, 0)
			
			if old then
				newMob:SetPrimaryPartCFrame(old.HumanoidRootPart.CFrame * offset)
			else
				newMob:SetPrimaryPartCFrame(map.Start.CFrame * offset)
			end
			
			newMob.Parent = workspace.Mobs
			newMob.HumanoidRootPart:SetNetworkOwner(nil)
			
			if newMob.Config:FindFirstChild("IsBoss") then
				newboss = newMob
				BossEvent:FireAllClients(newboss)
			else
				newboss = nil
			end
			
			local movingTo = Instance.new("IntValue")
			movingTo.Name = "MovingTo"
			movingTo.Parent = newMob
			
			for i, object in ipairs(newMob:GetDescendants()) do
				if object:IsA("BasePart") then
					PhysicsService:SetPartCollisionGroup(object, "Mob")
				end
			end
			
			newMob.Humanoid.Died:Connect(function()
				dpartiele:FireAllClients(newMob)
				newMob:Destroy()
			end)

			if old then
				coroutine.wrap(mob.RandomMove)(newMob,old, map)
			else
				coroutine.wrap(mob.Move)(newMob, map)
			end
		end
		
	else
		warn("Requested mob does not exist:", name)
	end
end

return mob
````Preformatted text`

is this part even firing?

newMob.Humanoid.Died:Connect(function()
	dpartiele:FireAllClients(newMob)
	newMob:Destroy()
end)
1 Like

Well It’s normally firing but on That Random Error 2
No.

is there anything in his Code different from the other characters which do work?
what about the Model itself, are there different things set on the Humanoid in relation to other characters?

1 Like

maybe the problem is it’s starting health being 0?

1 Like

I don’t think so

Well… maybe i don’t need to fix it? it’s not happened everytimes it’s only happened sometimes

that’s even more weird tbh, but oh well, good luck with this thing

1 Like

you could try using this:

local hum = script.Parent.Humanoid

local mob = {"Internet destoryer","Molten","Slime","Hidden Upgraded Error","Blue Screen","Data Transmitter"}

hum.HealthChanged:Connect(function(newhealth)
	if newhealth <= 0 then
		local random = mob[math.random(1,#mob)]
		game.ReplicatedStorage.Events.Mystery:Fire(random,1,workspace.Map:FindFirstChildOfClass("Folder"),script.Parent)
script.Parent:Destroy()
	end
end)

Well,It’s could work but that my towers broke because there was the line count kill when kill enemy but enemy was got destroy first so it’s can’t check

have you checked if the health is less than or equal to zero?
are you sure its not just a ui visual bug?
are you sure the script that checks for the death is even running?
are you sure the event is firing? use a print to find out
if you are using .HealthChanged, im pretty sure it does not fire when the humanoid dies, so try using .Died

1 Like

Maybe change the way you are executing your script : try to wrap all the code of the NPC while he’s alive in a
while [npc is alive] do
and after the while is the code when the npc died.
The [npc is alive] could be humanoid.Health > 0

1 Like