Humanoid never moves but the script still works fine

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    i want the humanoid to move but it doesnt move

  2. What is the issue? Include screenshots / videos if possible!
    Humanoid is stuck at the same position, it never moves from the spot even when the script says its moving (i tried using the print debug method and the script works fine just the humanoid doesnt move)

  3. What solutions have you tried so far? Did you look for solutions on the Creator Hub?
    I tried using :WaitForChild() for the variables
    I also tried using humanoid.MoveToFinished() but it doesnt work too,

script works perfectly fine, its just the humanoid doesnt move i know this because i tested it with print() debug method and the script goes through the if statements and the walking track animation plays aswell

local module = require(script.Parent.ModuleScript)
local npc = script.Parent
npc:WaitForChild("HumanoidRootPart")
npc:WaitForChild("EnemyHumanoid")
local humanoid = script.Parent:WaitForChild("EnemyHumanoid")
local animator = humanoid:WaitForChild("Animator")

local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://127283851729330"
local track = animator:LoadAnimation(animation)
local debounce = false
game:GetService("RunService").Heartbeat:Connect(function()

	module.GetClosestEnemy(npc)

	if module.ClosestEnemy and module.ClosestRoot then
		if module.ClosestDistance < 12.5 then
			
			local backPos = npc.HumanoidRootPart.Position - npc.HumanoidRootPart.CFrame.LookVector * 2
			
			npc.EnemyHumanoid:MoveTo(backPos)
			if debounce == false then
				debounce = true
				track:Play()
			end
			humanoid.MoveToFinished:Connect(function(reached)
				if reached then
					debounce = false
					track:Stop()
					
				end
			end)
			
			
			
			return
		end
		if module.ClosestDistance < 17.5 then
			npc.EnemyHumanoid:MoveTo(npc.HumanoidRootPart.Position)
			
			return
		end
		
		npc.EnemyHumanoid:MoveTo(module.ClosestRoot.Position)
		if debounce == false then
			debounce = true
			track:Play()
		end
		humanoid.MoveToFinished:Connect(function(reached)
			if reached then
				debounce = false
				track:Stop()
			end
		end)
		
	end
end)

1 Like

you sure you’ve unanchored the enemy’s primarypart? and calling moveto() in a heartbeat is not good, you can make a simple repeat task.wait outside loop until the target you want and then call the moveto outside the loop (idk if im being clear) and keep the target check, and distances inside the loop, while on the outside you wait it to not be nil

1 Like

yeah everything is unanchored, i might try while task.wait do, it does sound like a viable option

You’re moving the npc to itself if the distance is under a certain amount, are you far enough away?

It’s never checked if the debounce is true.

Can you provide the module so I can test the code myself?

1 Like

what does the humanoid layout look like? a easy way to check if the humanoid works is try to knock it over. If it gets knocked over, and it dosent get up, ur humanoid isnt set up properly