I have recently been experimenting with making a NPC walk randomly by a certain point. It walks to the point without any problems but once reaching it is supposed to walk to randomly to points around it. However, when reaching the point the NPC only walks back and forth in the Y axis never changing it's X position. I am really confused by this. Here is the script:

while true do wait ()
script.Parent.Humanoid.WalkToPart = workspace.A
C = math.random(1,3) -- a variable to cause the NPC
N = Vector3.new(math.random(-10,10),0,math.random(-10,10))
print (N) -- prints a number like (X,Y,X)
if C == 1 then
N = P
else
	script.Parent.Humanoid.WalkToPoint = N
	--This should make it walk to a point like (X,Y,Z) but instead walks to (0,Y,Z)!
	--Something I tried to figure out the problem
	Part = Instance.new("Part")
	Part.Parent = workspace
	Part.Transparency = 0.7
	Part.CanCollide = false
	Part.Anchored = true
	Part.Shape = ("Ball")
	print ("NewPart")
	Part.Position = workspace.A.Position + N
	Part.Color = Color3.new(1,0,0)
	--creates a part at (5,0,-5) 
	--N appears to be able to create parts in the right position
end

wait ()
if P ~= N then
	--you can probably ignore the animation stuff since it is not the problem

 
-- Create new 'Animation' instance
local Animation = Instance.new("Animation")
-- Set its 'AnimationId' to the corresponding animation asset ID
Animation.AnimationId = script.walk.RunAnim.AnimationId
 
-- Load animation onto the humanoid
local AnimationTrack = humanoid:LoadAnimation(Animation)
 AnimationTrack:Stop()
-- Play animation track
AnimationTrack:Play()



script.Parent.Humanoid.MoveToFinished:wait()
AnimationTrack:Destroy()
Part:Destroy()
else local Animation = Instance.new("Animation")
Animation.AnimationId = script.idle.Animation1.AnimationId
AnimationTrack = humanoid:LoadAnimation(Animation)
AnimationTrack:Play()
wait(2)
AnimationTrack:Destroy()
end
P = N
end

1 comment

0

use Humanoid:Move(V3.New()) instead of .WalkToPoint