Ok, so i tried making an ncp that tracks the player, but it keeps on going back and forth, which slows him down alot.
My code:
local hum = script.Parent
local HumRootPart = hum.Parent.PrimaryPart
local RServ = game:GetService("RunService")
local plrs = game:GetService("Players")
local TargetDist = 100
local StopDist = 5
local anim = script.Parent:LoadAnimation(script.Parent.Parent.Run)
local PathFindingService = game:GetService("PathfindingService")
local Kiddo = workspace:FindFirstChild("WanderFolder"):GetChildren()
local ChildInBasement = math.random(1,#Kiddo)
local RandomInt = Kiddo[ChildInBasement]
local Waypoints = workspace.WanderFolder:GetChildren()
local AttaccDeeztance = 7
local Event = game:GetService("ReplicatedStorage").RemoteEvents.Jumpscares.Experiment001.SpookiExpewimente
local AttaccWait = 1
local LastAttacc = tick()
local path = PathFindingService:CreatePath()
function FindNearestPlayer()
local plrList = plrs:GetPlayers()
local nearestPlr = nil
local dist = nil
local direction = nil
for _, player in pairs(plrList) do
local char = player.Character
if char then
local distVector = (player.Character.HumanoidRootPart.Position - HumRootPart.Position)
if not nearestPlr then
nearestPlr = player
dist = distVector.Magnitude
direction = distVector.Unit
elseif distVector.Magnitude < dist then
nearestPlr = player
direction = distVector.Unit
dist = distVector.Magnitude
end
end
end
return nearestPlr, dist, direction
end
RServ.Heartbeat:Connect(function()
local nearestPlr, distance, direction = FindNearestPlayer()
if nearestPlr then
if distance <= TargetDist and distance >= StopDist then
path:ComputeAsync(hum.Parent.PrimaryPart.Position, nearestPlr.Character.PrimaryPart.Position)
local Waypoints = path:GetWaypoints()
path.Blocked:Connect(function()
end)
for i, Waypoint in pairs(Waypoints) do
if Waypoint.Action == Enum.PathWaypointAction.Jump then
hum.Jump = true
end
hum:MoveTo(Waypoint.Position)
hum.MoveToFinished:Wait()
end
else
hum:Move(Vector3.new())
end
end
end)```
Any help is appeciated!