Help with NPC respawning script

So I wanted to make an NPC respawning script for my game, but it wasn’t working, video:

As you can see in the video, when the NPC respawns, it has 0 health, and just glitches out.

script:

script.Parent.Humanoid.Died:Connect(function()
	wait(2)
	script.Parent:Destroy()
	game.ReplicatedStorage.NPCs.CaveMan.Humanoid.Health = 100
	game.ReplicatedStorage.NPCs.CaveMan:Clone().Parent = workspace
end)

Any help would be appreciated!

1 Like

You’re doing script.Parent:Destroy() before calling it, meaning your script immediately stops.

Instead, you can do this:

script.Parent.Humanoid.Died:Connect(function()
	wait(2)
	game.ReplicatedStorage.NPCs.CaveMan.Humanoid.Health = 100
	game.ReplicatedStorage.NPCs.CaveMan:Clone().Parent = workspace
	script.Parent:Destroy()
end)
1 Like

The same thing happens, the NPC just constantly respawns with 0 health.

You cant change the humanoid’s health if this is in 0. But you can clone a NPC with more health.

1 Like

I was doing exactly that and it wasn’t working. I tried removed the game.ReplicatedStorage.NPCs.CaveMan.Humanoid.Health = 100, and that still didn’t work.

It’s game.ReplicatedStorage.NPCs.CaveMan.Humanoid’s Health in 100?

1 Like

Try this:

local new = script.Parent:Clone()
script.Parent.Humanoid.Died:Connect(function()
	wait(2)
	new.Parent = workspace
    script.Parent:Destroy()
end)
2 Likes

The exact same thing happens, I’ve tried like 10 different scripts like this, and none of them worked.

Did you check if the human’s health it’s the same as the Gui frame?

1 Like

I changed the humanoid of the NPC to always show the built in health bar, and the same thing happened to that health bar as the GUI health bar, so I am pretty sure it isn’t the GUI.

EDIT: It works for some reason, I just lifted the NPC off the ground and now it works.