NPC Cframe.LookAt wont tween

Henlo frens

I am making AI that shoots gun when close enough.
However i face another roadblock.
I want to tween its primaryPart CFrame.LookAt to player position.
However, my child (the npc) is misbehaving.
Please help.
For example.


he us supposed to aim his gun at me and only does so at the start because of AutoRotate.

Here code:


function idle(v)
	local humanoid = v:WaitForChild("Humanoid")
	local animator = humanoid:WaitForChild("Animator")
	
	local runAnim = Instance.new("Animation")
	runAnim.AnimationId = "rbxassetid://14284219075"
	local runAnimTrack = animator:LoadAnimation(runAnim)
	
	local idleAnim = Instance.new("Animation")
	idleAnim.AnimationId = "rbxassetid://15572125859"
	local idleAnimTrack = animator:LoadAnimation(idleAnim)
	
	local shootAnim = Instance.new("Animation")
	shootAnim.AnimationId = "rbxassetid://15571931600"
	local shootAnimTrack = animator:LoadAnimation(shootAnim)
	
	task.defer(function()
		
		local distance = nil
		local closestPlayer = nil
		local shootDb = false
		local pathfinding = true
		
		runAnimTrack:Play()
		
		runService.Heartbeat:Connect(function()
			
			closestPlayer = simplePath.GetNearestCharacter(v.PrimaryPart.Position)
			if closestPlayer ~= nil then
				distance = (v.PrimaryPart.Position - closestPlayer.PrimaryPart.Position).Magnitude
				
				if shootDb == false and distance <= 35 then
					local x = v.PrimaryPart
					local a = x.Position
					local b = closestPlayer.Torso.Position
					
					v.Humanoid.AutoRotate = false
					runAnimTrack:Stop()
					
					local Tween = tweenService:Create(x, TweenInfo.new(1), {CFrame = CFrame.lookAt(a, b)})
					Tween:Play()
				
					
					shootAnimTrack:Play()
					pathfinding = false
					shootDb = true
					
					shootAnimTrack:Play()
					wait(1)
					v.Handle.Beam1.Enabled = true
					v.Handle.Beam2.Enabled = true
					wait(1)
					v.Handle.Beam1.Enabled = false
					v.Handle.Beam2.Enabled = false
					pathfinding = true
					v.Humanoid.AutoRotate = true
					wait(3)
					shootDb = false
				end
			
				
				if pathfinding then
					local path = simplePath.new(v)
					path:Run((closestPlayer.PrimaryPart.Position - CFrame.new(v.HumanoidRootPart.Position, closestPlayer.PrimaryPart.Position).LookVector * 30))
				end
			

			end
		end)

	end)
	
end

Okay dropping the character, this is driving me nuts and i just wanna get this over with, i have math.huge more bigger problems to fix other than this and i just wanna get this done.

3 Likes

Have you considered Lerping?

1 Like

How exactly would i apply this or use this as a replacement to tweening CFrame:lookAt ?? or use it to tween the direction that the npc is facing??

1 Like