- What do you want to achieve? Keep it simple and clear!
I want to tweak a script I have that causes an issue with a brief freeze in my NPC walking.
- What is the issue? Include screenshots / videos if possible!
I’ve been stuck on a line of code I use to tweak the NPC to turn to an aggro’d player while the NPC is walking using cframe:lerp. This does work but it causes an issue that i’ve been trying to search and fix for a few hours now, the issue being that the NPC briefly freezes, before continuing to walk. The script runs on a server script for those wondering.
Here’s the part of the code I use to turn the NPC
local function CfLerpHRP(TheHumanoidPart, TheAggroPlayer) -- Unrelated, but activates using task.spawn
while true do
task.wait(1) -- Originally was 0.07, but changed to 1 second to make the brief freezing more visual on the video.
TheHumanoidPart.CFrame = TheHumanoidPart.CFrame:Lerp(CFrame.new(TheHumanoidPart.CFrame.Position, TheAggroPlayer.Character.Torso.Position), 0.2)
end
end
I’ve used other alternatives, such as AlignOrientation which sort-of works but causes the NPC to look up if the player is somewhere high, which I don’t want it to.
A weird thing I’ve found out is that the brief freezing only becomes a problem when I want to rotate an NPC, and not it’s position.
How can I fix this? Is slightly rotating an NPC inevitable with a brief freeze on Roblox?