[HELP] Making an NPC turn

Hi! I’m looking for help on making an NPC turn and face a specific direction when a button is clicked.

For example:

NPC is called NPCA

and once a button is clicked, NPCA will now have a different orientation and be facing another direction. I’m looking to make it turn smoothly and so it doesn’t just teleport to face a new directon.

I’ve tried to use tweenservice to change it’s orientation but it’ll end up just moving the HumanoidRootPart or one part within the NPC and not the whole NPC.

Any help is appreciated,
thanks! :slight_smile:

2 Likes

I have not tested it but it might work:
Make a part and make it face a direction and name it for example X for the X direction Z for the Z direction. Then make your buttons. Make ALL the parts face it’s name so Z would look at the Z axis.

local direction = workspace.Z
local NPCA = workspace.NPCA
button.MouseClick:Connect(function()
if button.Name == "Z" then
NPCA.PrimaryPart.CFrame.lookVector = direction.lookVector
end
end)

If it helps please make it a solution :slight_smile:

1 Like

Hi! I had the clickdetector etc previously set up but I’m getting an error… did I remove a important line of script or? I think I’ve give the location of everything needed etc? (All is in workspace etc…)

I forgot use direction.lookVector

1 Like

Will try with that right now.

Update:
image|690x29

I forgot XD
direction.CFrame.lookVector

I believe you may also need to use :SetPrimaryPartCFrame()

1 Like

WHen you want to get the where an object is facing, use Part.CFrame.lookVector

try this

local angleToChange = 90

local HRP = NPCA.HumanoidRootPart

game:GetService("TweenService"):Create(HRP, TweenInfo.new(1), {CFrame = CFrame.new(HRP.Position, HRP.Position + (HRP.CFrame * CFrame.Angles(0, math.rad(angleToChange), 0)).LookVector)}):Play()
1 Like

So sorry that I forgot XD (30 chars)