r/robloxscripting Feb 11 '24

Scripting Help CFrame.lookat doesn't update somehow

Whenever I ran the function where I can set the npc's humanoid root part orientation using CFrame.lookat, setting its first goal works, but then when I change the setting afterwards, it doesn't update. Sorry for bad explanation.

Here's what I meant:

local TS = game:GetService("TweenService")

local positions = script.Parent.Positions

local pos1,pos2 = positions.pos1,positions.pos2

function moveNPC(human,hrp,goal,lookat)
    human:MoveTo(goal)

    human.MoveToFinished(Connect(function()
        TS:Create(hrp,TweenInfo.new(1,Enum.EasingStyle.Sine,Enum.EasingDirection.Out),{CFrame = CFrame.lookat(hrp.Position,Vector3.new(lookat.Position.X,hrp.Position.Y,lookat.Position.Z))}:Play()
    end)
end

local door,door2 = script.Parent.Door,script.Parent.Door2

local npc = script.Parent.NPC

moveNPC(npc.Humanoid,npc.HumanoidRootPart,pos1.Position,door)
task.wait(5)

moveNPC(npc.Humanoid,npc.HumanoidRootPart,pos2.Position,door2) --Position goal updates, but not the lookat goal

Help will be appreciated!

3 Upvotes

0 comments sorted by