the npc is suppose to attack but it wont idk why the animation wont play either how do i fix?
local torso = script.Parent.HumanoidRootPart
local h = script.Parent.Humanoid
local spawnCF = script.Parent.HumanoidRootPart.CFrame
local anim = h:LoadAnimation(script.Parent.Tool.Animation)
local att = false
function findplayer()
for _,v in next,game.Players:GetPlayers()do
if v.Character then
local char = v.Character
if char:FindFirstChild("Humanoid")and char:FindFirstChild("HumanoidRootPart") then
local ptorso = char.HumanoidRootPart
if(ptorso.position - torso.Position).magnitude <= 7 then
att = true
end
if(ptorso.position - torso.Position).magnitude <= 27 then
return v
end
end
end
end
return nil
end
while wait()do
local player = findplayer()
if player ~= nil then
h:MoveTo(player.Character.HumanoidRootPart.position)
if att == true then
anim:Play()
wait(.8)
att = false
end
else
h:MoveTo(spawnCF.p)
end
end