When I finished my PathFinding script, I immediately tested it. When I did, it was fine and dandy, until when the NPC died, the PathFinding broke.

I'm not entirely sure if it's because of the Humanoid being renamed to EnemyHum.

Here's my respawn script: (Located inside of NPC's character)

name = "EnemyHum"

robo = script.Parent:Clone()

while true do
	wait(10)
	if script.Parent.EnemyHum.Health < 1 then
		robot = robo:clone()
		robot.Parent = script.Parent.Parent
		robot:MakeJoints()
		script.Parent:remove()
	end
end

Here's my PathFinding script: (Located inside of NPC's character)

local player = game.Players.LocalPlayer or game.Players.PlayerAdded:Wait()
local character = player.Character or player.CharacterAdded:Wait()
while not character do
	character.AncestryChanged:Wait()
end
local hrp = character:WaitForChild('HumanoidRootPart')
local hum = character:WaitForChild('Humanoid')
local enemyHum = script.Parent.EnemyHum
local enemyHRP = script.Parent.HumanoidRootPart

local enemyHRPcf = enemyHRP.CFrame
while wait() do
	if (enemyHRP.Position - hrp.Position).Magnitude < 30 then
		enemyHum:MoveTo(hrp.Position)
	elseif (enemyHRP.Position - hrp.Position).Magnitude > 30 then
		enemyHRP.CFrame = CFrame.new(85.98, 81.974, 130.905)
	end
end

There are no errors found in the output tab.

Any help please?

2 comments

0

btw a better way to do respawning is to check if the NPC has died and then do a cooldown so it doesnt respawn instantly or 10 seconds later randomly

0

Oh okay.