Npc/Soldier won't move

Can you guys check why my script wont work? The soldiers are supposed to kill and chase anyone near them that isn’t tagged. The problem is they won’t move.

local RomanRoot = script.Parent.HumanoidRootPart
local RomanHumanoid = script.Parent.Humanoid
local ss = game:GetService("ServerStorage")
local collectionService = game:GetService("CollectionService")
	
local function findenemy()
	local aggro = 6000
	local target = nil
	local dmgrange = 7
	for i, v in pairs(game.Workspace:GetChildren()) do
		
		if collectionService:HasTag(v.Parent, "Iskandar") then 
			return
		else 
				
				
		local human = v:FindFirstChild("Humanoid")
		local root = v:FindFirstChild("HumanoidRootPart")
		if human and root and v ~= script.Parent then
		
		
			if v.Name ~= "Soldier" then
			if (RomanRoot.Position - root.Position).Magnitude < aggro then
				aggro = (RomanRoot.Position - root.Position).Magnitude
				target = root
				if (RomanRoot.Position - root.Position).Magnitude <= dmgrange then
						human.Health = human.Health - 15
				end
			end
		end
	end
	return target
end
				
				
			end
		end
			
				
		 
		
while true do
	wait()
	local torso = findenemy()
	if torso then
		RomanHumanoid:MoveTo(torso.Position)	
	end
	
end
1 Like

Is it anchored by any chance?

2 Likes

nope, i just checked it’s not`````````

1 Like

Maybe try setting this to “humanoid”? Or something similiar, I barely know scripting. I just wanna try to help.

2 Likes

oh i just checked it wouldnt and didnt work since local target = nil is already there before humanoid is defined. Thanks anyway

Ah alright, goodluck with your game. :slight_smile:

1 Like

return breaks the whole for loop I don’t think you accounted for that

1 Like

Ohh thanks I actually didn’t know that I thought it would just continue the script below it

Uhm so I just tried removing the return and it still didnt work. Any ideas?

try using this on a blank humanoid, maybe you moved it and broke the welds

1 Like

Still didn’t work thanks anyways