So this is the script that I created for the AI
local Pathfinding = game:GetService("PathfindingService") local NPC = script.Parent local Hum = NPC.Harmoid local RootPart = NPC.HumanoidRootPart local RunAnim = Hum:LoadAnimation(NPC.RunAnim) local IdleAnim = Hum:LoadAnimation(NPC.IdleAnim) local RootChase = nil local HumChase = nil local Plr = nil local PlayerList = game.Players local function Move() local pathfinder = Pathfinding:FindPathAsync(RootPart.Position,RootChase.Position) local way = pathfinder:GetWaypoints() for i,v in pairs(way) do Hum:MoveTo(v.Position) Hum.MoveToFinished:wait() end end local function Mag(point) return (RootPart.Position - point.Position).magnitude end IdleAnim:Play() while true do wait(5) local Lowest = math.huge for _,plr in pairs(PlayerList:GetPlayers()) do if plr.Character then local pchar = plr.Character local phum = pchar.Humanoid if phum.Health > 0 then local proot = pchar.HumanoidRootPart local Mager = Mag(proot) if Mager<Lowest then Lowest = Mager RootChase = proot HumChase = phum Plr = plr end end end end RunAnim:Play() while Plr do print('Activating!') Move() end RunAnim:Stop() end
That's everything :P
First thing is: At the printing function. It activates more than 30 times O_O
Second thing is: at the Hum.MoveToFinished:wait() part it has a slow delay and glitchy.