I have a code that is run in a coroutine. It’s supposed to make the NPC look at the target as it moves. But since the loop sets the npc’s position, it isn’t moving and is staying locked in place (although it still faces target).
How can I make it so that it moves and looks at the same time?
Code:
local function LookAt(targoot)
while wait() do
local goal = {CFrame = CFrame.new(script.Parent.HumanoidRootPart.Position,targoot.Position)}
tweenserv:Create(script.Parent.HumanoidRootPart,TweenInfo.new(2),goal):Play()
end
end
Something that helps with solving bugs like this would be to use print statements to show where where in the script it’s at when you’re doing specific things. You should also try printing out the variables that may be in question to see if they have the values that you are expecting. This has helped me solve countless number of bugs. Or you could just use the Lua debugger.
You should either cframe them with bodygyro or with the root motor6d because setting the CFrame to the same position won’t work and won’t let the npc move either.