NPC Doesn't Do Damage After Respawn

When the NPC first spawns in it does damage to the player, but when you kill the NPC and it respawns, it doesn’t attack/do damage to the player.

Here is the Attack Script:

game.Players.PlayerAdded:Connect(function(plr)

while wait(2)do

local UpperTorso = script.Parent.Parent.HumanoidRootPart

local Hum = script.Parent.Parent.Humanoid

local character = game.Workspace:WaitForChild(plr.Name)

local charupper = character:WaitForChild("HumanoidRootPart")

local charhum = character:WaitForChild("Humanoid")

local deb = true

UpperTorso.Touched:Connect(function(hit)

if hit.Parent == character then

if deb == true then

deb = false

local attack = script.Parent.Parent.Humanoid
local anim = attack:LoadAnimation(script.attack.AttackAnim)

anim:Play()
script.attack.AttackSound:Play()

charhum.Health = charhum.Health - 5

wait(9999) --time between the hits

deb = true

end

end

end)

end

end)

Here is the Respawn Script:

robo=script.Parent:clone()

while true do
	wait()
	if script.Parent ~= nil then
	if script.Parent.Humanoid.Health <= 1  then
		wait(3)
		robot=robo:clone()
		robot.Parent=script.Parent.Parent
		robot:makeJoints()
		script.Parent:remove()
	end
	end
end

Can anyone please help me fix it so that the NPC still can damage player after death/respawn?

Try to replace damage script with this
local rarm = script.Parent:FindFirstChild(“Right Arm”)
local larm = script.Parent:FindFirstChild(“Left Arm”)

function dmg(hit)
if hit.Parent ~= nil then
local hum = hit.Parent:findFirstChild(“Humanoid”)
if hum ~= nil then
hum.Health = hum.Health -10
end
end
end

rarm.Touched:connect(dmg)
larm.Touched:connect(dmg)

1 Like

Replaced and tested but NPC does 0 damage. I’m also hoping to have it hit every 3 seconds.

Oh and the NPC is R15.

Do you try changing local hum =hit.Parent:findFirstChild(“Humanoid”) to . . .
local hum =hit.Parent:findFirstChild(“HumanoidRootPart”)
If this not work test the game in roblox studio wait for npc to respawn and check inside of model for scripts

Fixed! I had to change right arm and left arm to R15 body parts. Now I have to try and add timing to it. Thanks.

2 Likes