NPC Moving at the same speed regardless of the walk speed

Like the title says, the NPC I am working on continuously moves the same speed, regardless of what its WalkSpeed is set to.

I’ve tried messing with the while true do wait() time, but that hasn’t worked, and now I am stuck.

This video shows it with 18 WalkSpeed:

This video shows it with 100 WalkSpeed:

here’s the script if anyone is curious:


-- Services
local Pathfinding_Service = game:GetService("PathfindingService")


-- Important variables --
local Enemy_Folder = script.Parent
local AI_Config = Enemy_Folder:WaitForChild("AI_Config")

-- NPC Variables --
local Enemy_Model = Enemy_Folder.Parent
local My_Root = Enemy_Folder.Parent:WaitForChild("HumanoidRootPart")
local My_Humanoid = Enemy_Folder.Parent:WaitForChild("Humanoid")

-- AI Configs --
local Agro_Distance = AI_Config:WaitForChild("Agro_Dist").Value
local Damage = AI_Config:WaitForChild("Damage").Value
local Speed = AI_Config:WaitForChild("Speed").Value
local Running_Animation = AI_Config:WaitForChild("Running_Animation").Value
local Walking_Animation = AI_Config:WaitForChild("Walking_Animation").Value
local Render_Speed = AI_Config:WaitForChild("Render_Speed").Value

local AI_Can_Jump = AI_Config:WaitForChild("AI_Can_Jump").Value
local AI_Can_Climb = AI_Config:WaitForChild("AI_Can_Climb").Value

local Path = Pathfinding_Service:CreatePath()


-- Bool Variables --
local Running = AI_Config:WaitForChild("Running")
local Walking = AI_Config:WaitForChild("Walking")

My_Root:SetNetworkOwner(nil)

while true do
	task.wait()
	for i,v in pairs(game.Workspace:GetChildren()) do
		local root_part = v:FindFirstChild("HumanoidRootPart")
		if root_part then
			if (root_part.Position - My_Root.Position).magnitude <= Agro_Distance and v ~= Enemy_Model and not v:FindFirstChild("Enemy_Contents") then
				print(v.Name.. " is within the distance of this NPC.")
				Path:ComputeAsync(My_Root.Position, root_part.Position)
				print(Path.Status)
				if Path.Status == Enum.PathStatus.Success then
					for i,c in pairs(Path:GetWaypoints()) do
						My_Humanoid:MoveTo(c.Position)
					end
				end
			end
		end
	end
end

Any advice given would be appreciated. I’m honestly stuck.

1 Like

I may be totally wrong here but I’m your script you got the integer speed. I think you are not setting the speed to the variable. Just a thought.

It isn’t moving at the same speed, it’s just stopping at the same speed. You could try calculating the direction between the NPC and the pathway point and use :Move(Direction: Vector3) instead of :MoveTo(Position: Vector3).

how would I go about obtaining this directional value?

local Difference: Vector3 = PathwayPoint - NPC.HumanoidRootPart.Position
local Direction: Vector3 = Difference.Unit

Also if it’s necessary, in order to stop the NPC from moving in the last direction you parsed to the :Move function, use Humanoid:Move(Vector3.new(0, -1, 0)).

1 Like

it kinda just rotates sporadically

local Difference = c.Position - My_Root.Position|

local Direction = Difference.Unit|
My_Humanoid:Move(Direction)|

What’s the WalkSpeed in this?

\\

The walkspeed of this Enemy NPC has been set to 18