NPC Health Bar Doesn’t Restore After Respawn - Avatar Morph System Help

:wave: Hello,

I’m working on a script to morph an NPC into any player’s avatar when a username is typed in chat. This is part of a test project using the Roblox FPS System template for background mechanics. This is not intended for official publishing.

  1. What do I want to achieve?
    I want the NPC to morph into a player’s avatar on command, and when it dies, it should respawn at the same position with full health and the same avatar.

  2. What is the issue?
    After the NPC dies and the respawn logic runs, the health bar does not restore properly, the NPC looks dead and can’t be “revived,” even though the script sets health to max. I’m including a video & screenshot attachment below to show this behavior.


Here’s a screenshot for those who cannot see the video.

  1. What solutions have I tried?
    I’ve used humanoid:ApplyDescription() and reset health with humanoid.Health = humanoid.MaxHealth inside a respawn function. I animate the NPC’s name during respawn to show a “Respawning…” message. I’ve searched the Creator Hub and DevForum but haven’t found a solution that fully restores health without recreating the NPC.

  2. The script in question with explained parts:

local npc = script.Parent
local humanoid = npc:FindFirstChildOfClass("Humanoid")
local Players = game:GetService("Players")

local currentlyMorphing = false
local currentUsername = npc.Name
local rememberedDescription = nil

-- Morph NPC into a user's avatar and remember the description
local function morphToUser(username)
	if currentlyMorphing then return end
	currentlyMorphing = true

	local success, userId = pcall(function()
		return Players:GetUserIdFromNameAsync(username)
	end)

	if not success then
		warn("Username not found:", username)
		currentlyMorphing = false
		return
	end

	local success2, description = pcall(function()
		return Players:GetHumanoidDescriptionFromUserId(userId)
	end)

	if not success2 then
		warn("Failed to get avatar description for", username)
		currentlyMorphing = false
		return
	end

	humanoid:ApplyDescription(description)
	npc.Name = username
	currentUsername = username
	rememberedDescription = description
	currentlyMorphing = false
end

-- Animate the name while waiting to respawn
local function animateRespawnName(callback)
	local states = { "Respawning", "Respawning.", "Respawning..", "Respawning...", "Respawning....", "Respawning....." }
	coroutine.wrap(function()
		for _, state in ipairs(states) do
			npc.Name = state
			task.wait(0.3)
		end
		callback()
	end)()
end

-- Respawn the same NPC using remembered avatar and heal
local function respawnNPC()
	local position = npc:GetPrimaryPartCFrame() -- where it died

	animateRespawnName(function()
		npc:SetPrimaryPartCFrame(position)

		if rememberedDescription then
			humanoid:ApplyDescription(rememberedDescription)
			npc.Name = currentUsername
		end

		humanoid.Health = humanoid.MaxHealth
	end)
end

-- When NPC dies
humanoid.Died:Connect(function()
	respawnNPC()
end)

-- Listen for player chat
Players.PlayerAdded:Connect(function(player)
	player.Chatted:Connect(function(message)
		local username = message:match("^(%w+)$")
		if username then
			morphToUser(username)
		elseif message:lower() == "!fix" then
			respawnNPC()
		end
	end)
end)


I would really appreciate any help or insights on how to fix the health bar so the NPC fully revives after death without needing to recreate the entire model.

Thanks so much!

1 Like

Disable the Dead State on the humanoid, as you are using the same humanoid which means it will go in the Dead State when reaching 0 health and it cannot leave that state once it is entered

Humanoid:SetStateEnabled(Enum.HumanoidStateType.Dead, false)

then use Humanoid.HealthChanged to detect when the humanoid is below 0 health, and then run your respawning code

Humanoid.HealthChanged:Connect(function(NewHealth)	
		if NewHealth <= 0 then
		respawnNPC()
        end
	end)
1 Like

Doing this removes the ability for the humanoid to die though.

My suggestion for OP is to handle death when the character reaches 0 health.

then you can just use HealthChanged to detect when the humanoids health moves below 0

1 Like

This should work, hopefully the solution as well.

yeah i use it whenever i make a boss fight since if the boss dies regularly and its limbs fall off then i cant make a cool death animaton :pensive:

Can’t you just disable “BreakJointsOnDeath”?

last time i checked i dont think humanoids can play animations while in the dead state but that may have changed now

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