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?