I have AI enemies that do damage to the player, when the player dies, they respawn, I also have a sword which I can use to deal damage to the enemies. The damage works BEFORE they respawn, after the AI respawn my sword just breaks, my enemy is a model and inside that model is a humanoid named "Zombie". Whenever I try to swing my sword AFTER it has respawn my game gets laggy and I get an error message: "Zombie is not a valid member of Model" on Line 11.
My enemy respawn script
z = script.Parent
backup = z:clone()
game:GetService('Players').PlayerAdded:connect(function(player)
player.CharacterAdded:connect(function(character)
character:WaitForChild("Humanoid").Died:connect(function()
z:Remove()
wait(2)
backup.Parent = game.Workspace.Enemies
backup.Head:MakeJoints()
backup.Torso:MakeJoints()
wait(15)
z.Zombie.WalkSpeed = 16
end)
end)
if z == nil then
wait(4)
backup.Parent = game.Workspace.Enemies
backup.Head:MakeJoints()
backup.Torso:MakeJoints()
end
end)
My sword script that does damage to my enemy
local enemies = game.Workspace.Enemies:GetChildren() --// All the children of the enemies folder.
for i, v in pairs(enemies) do
if v:FindFirstChild("Zombie") then --// If the model has a humanoid
wait(1)
v.HumanoidRootPart.Touched:Connect(function()--// When the sword touches the npc
script.Parent.Activated:Connect(function() --// If you click holding the sword it will damage.
v.Zombie:TakeDamage(10) --// Npc takes 10 Damage
wait(1)
end)
end)
end
end
I believe this issue is because my respawn script removes the enemy from existence, thus removing the humanoid from existence. Except after the enemy comes back into Workspace it still doesn't work? Thanks!

2 comments
why in the if v:FindFirstChild("Zombie") then are you searching for "Zombie" rather than Humanoid? or is the Humanoid named that?
The humanoid is named Zombie