Making AI follow a constantly moving destination

  1. What do you want to achieve? Keep it simple and clear!
    I wanna learn how you can make an AI get to a destination that moves constantly with pathfinding. On a shorter note I want an AI to chase the player while not walking into objects. I don’t want to make the AI follow you when it finds you, I just want it to follow you forever.

  2. What is the issue? Include screenshots / videos if possible!
    I don’t know how.
    Script:

local Jenny = game.Workspace.JennyAnimated
local Humanoid = Jenny.Humanoid
local Humanoid2 = Jenny:WaitForChild(“Humanoid”)
local Player = game.Players:FindFirstChildWhichIsA(“Player”) or game.Players.PlayerAdded:Wait()
local PlayerC = Player.Character or Player.CharacterAdded:Wait()
local PlayerHRP = PlayerC:WaitForChild(“HumanoidRootPart”)
print(PlayerHRP)
local Jenny = script.Parent
local Humanoid = Jenny.Humanoid
local ray = Ray.new(Jenny.HumanoidRootPart.Position,PlayerHRP.Position)
game.Workspace.BrownDoor.Hitbox.Touched:Connect(function(hit)
if hit.Parent.Name == (“BrownKey”) then
Jenny.HumanoidRootPart.JennysTheme2:Play()
while true do
wait()
Humanoid:MoveTo(PlayerHRP.Position)
end
end
end)

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I’ve tried this:

local Humanoid = Jenny.Humanoid
local Humanoid2 = Jenny:WaitForChild(“Humanoid”)
local Player = game.Players:FindFirstChildWhichIsA(“Player”) or game.Players.PlayerAdded:Wait()
local PlayerC = Player.Character or Player.CharacterAdded:Wait()
local PlayerHRP = PlayerC:WaitForChild(“HumanoidRootPart”)
print(PlayerHRP)
local Jenny = script.Parent
local Humanoid = Jenny.Humanoid
local ray = Ray.new(Jenny.HumanoidRootPart.Position,PlayerHRP.Position)
game.Workspace.BrownDoor.Hitbox.Touched:Connect(function(hit)
if hit.Parent.Name == (“BrownKey”) then
local PFS = game:GetService(“PathfindingService”)
local path = PFS:CreatePath()
path:ComputeAsync(Jenny.HumanoidRootPart.Position,PlayerHRP.Position)
local WPs = path:GetWaypoints()
while true do
for i, waypoint in pairs(WPs) do
Humanoid2:MoveTo(waypoint.Position)
Humanoid2.MoveToFinished:Wait()
end
end
Jenny.HumanoidRootPart.JennysTheme2:Play()
while true do
wait()
Humanoid:MoveTo(PlayerHRP.Position)
end
end
end)