Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How would I make a NPC walk backwards?

Hello,

So I am trying to figure out how to do this. I would like to make an NPC walk backwards. I know I could disable auto rotate but with the project I am doing I would have to keep enabling it and disabling it. I was wondering if anyone has any other solutions. Could I place a brick inside the NPC and cframe that? Any help would be very much appreciated.

I found this but I am not sure if this would help with what I am trying to do. It would be nice if I could move the NPC to a point like you would with WalkToPoint but with Cframe

local Part = Workspace.Part -- this is the Part we will move
local newPos = Part.Position + Vector3.new(0,5,0) -- the position the Part will go to
local Time = 10 -- the time that the script will take to move the part
local Increment = 0.5 -- the Part will move 0.5 studs each time it moves
local Debounce = false
 
local Diff = newPos - Part.Position -- the difference between the two positions
local Mag = Diff.magnitude -- the distance between the two parts
local Direction = CFrame.new(Part.Position, newPos).lookVector
 
function MovePart() -- function to move the Part
	if Debounce then return end -- end the function if debounce is true
	Debounce = true -- make Debounce true so the function can't run
	for n = 0, Mag, Increment do
		Part.CFrame = Part.CFrame + (Direction * Increment)
		wait( (Time/Mag) * Increment )
	end
	Debounce = false -- set Debounce to false so the function can run again
end

1 answer

Simply use the Move or MoveTo functions of humanoids. The function Move causes NPC to walk a given direction. Use like so:

workspace.NPC.Humanoid:Move(Vector3.new(x,y,z))

You can also specify a boolean in second argument determine if the movement is relative to camera, but for NPC I wouldn't be concerned (it defaults to false anyway)

If want the NPC to move a specific point, use MoveTo, like so:

workspace.NPC.Humanoid:MoveTo(Vector3.new(x,y,z))

You can also specify a part for the second argument that it`ll attempt move to, which is nice because if it moves, point will also move stay the same relative distance. It defaults to nil, however, so you don't have to specify .

Hope I could help!

EDIT: Grammar (autocorrect causes far more mistakes than corrections :/)

1 comment

0

Thanks! That is not exactly what I was trying to do but I was able to achieve it another way. Thank you for your help :)

This discussion is preserved as it was. New answers, comments, and votes are closed.