So I have this NPC but it didn't turn by itself, so then I set it's CFrame to make it face the player when moving... and I guess it's better than nothing but it's turning is very choppy. Here's what I mean So is there any way I can make this guy move more naturally? Here's the script ``` wait(5)
script.Parent.AttackingPlayer.Value = ""
local range = 20
local function searchforplayer()
local ray = Ray.new(script.Parent.HumanoidRootPart.CFrame.Position, script.Parent.HumanoidRootPart.CFrame.LookVector * 500)
local part = game.Workspace:FindPartOnRay(ray)
if part then
if part.Parent:FindFirstChild("Humanoid") then
if game.Players:FindFirstChild(part.Parent.Name) then
print("Found player!")
return (part.Parent)
end
end
end
end
while true do
if script.Parent.AttackingPlayer.Value == "" then
print("Searching...")
if searchforplayer() == nil then
while searchforplayer() == nil do
wait(0.1)
if searchforplayer() ~= nil then
script.Parent.AttackingPlayer.Value = searchforplayer().Name
break
end
end
end
end
local path = game:GetService("PathfindingService"):CreatePath()
local prs = game.Workspace:FindFirstChild(script.Parent.AttackingPlayer.Value)
range = math.huge
path:ComputeAsync(script.Parent.HumanoidRootPart.Position, prs.HumanoidRootPart.Position)
local points = path:GetWaypoints()
local player = game.Workspace:FindFirstChild(script.Parent.AttackingPlayer.Value)
script.Parent.Parent.Points:ClearAllChildren()
for a, b in pairs(points) do
part = Instance.new("Part")
part.CanCollide = false
part.Size = Vector3.new(1,1,1)
part.Position = b.Position
part.Anchored = true
part.Transparency = 0
part.Parent = script.Parent.Parent.Points
end
if path.Status == Enum.PathStatus.Success then
for a, b in pairs(points) do
local hrp = player.HumanoidRootPart.Position
local lookto = Vector3.new(hrp.X, script.Parent.HumanoidRootPart.Position.Y, hrp.Z)
script.Parent.HumanoidRootPart.CFrame = CFrame.new(script.Parent.HumanoidRootPart.Position, lookto)
script.Parent.Humanoid:MoveTo(part.Position)
if b.Action == Enum.PathWaypointAction.Jump then
script.Parent.Humanoid.Jump = true
end
end
end
end```