Humanoid:MoveTo() not working at all

I’ve been trying to make a simple enemy bot script, in which the enemy just follows the player around and attacks if the player close enough. The problem I’ve been having is that the MoveTo function on the humanoid simply doesn’t work in my scripts. This is especially confusing since I’ve previously used MoveTo without having this issue. I have also tested the “Drooling Zombie” model found in the toolbox in the same place, which as far as I understand also uses MoveTo to move, although in a much more sophisticated manner than what I’m trying to do. It came to the point where is just followed the Roblox Tutorial on how to move a humanoid and even the simplest scripts won’t work. I have tested MoveTo on the character model instead, which does move the character but teleports it rather than “slides” it which is obviously not desirable when you’re trying to make an NPC. This problem occurs both when run on the client and when run on the server, as well as in both synchronous and asynchronous threads.

Extremely simple script:

-- This is the copy I made of the roblox tutorial's first block of code 
local dummy = workspace:WaitForChild("Dummy")
local hum = dummy:WaitForChild("Humanoid")
local pointA = workspace:WaitForChild("Model")
print (dummy, hum, pointA) -- None of these print nil
wait(10) --[[ This is because I thought that maybe MoveTo wasn't working because 
the world wasn't fully loaded in yet but that was not the case]]
print ("Moving npc...")
hum:MoveTo(pointA.PrimaryPart.Position)

Slightly more advanced script:

local Demon = game:GetService("ReplicatedStorage").Demon

local function demonAI (demon)
	print ("init demon")
	if not demon:FindFirstChild("Humanoid") or not demon:FindFirstChild("HumanoidRootPart") then print ("DemonAI is only available inside of a humanoid"); return end

	local uis = game:GetService("UserInputService")
	local ps = game:GetService("PhysicsService")
	
	local demonTarget = game.Players.LocalPlayer
	local configs = demon.Configurations

	local difficulty
	local clientIsMobile = uis.TouchEnabled -- This is just to make life a little easier for mobile players
	if clientIsMobile then difficulty = 2 else difficulty = 0.3 end

	local canAttack
	local function attack(difficulty)
		if canAttack then
			canAttack = false
			
			local dmg = configs.BaseDamage.Value
			if difficulty == 2 then dmg -= dmg/3 end 
-- BaseDamage = 10 obviously I haven't tweaked these values too much since other problems came in the way
			demonTarget.Character.Humanoid:TakeDamage(dmg)
			
			wait(configs.AttackSpeed.Value)
			canAttack = true
		end
	end

	while wait(difficulty) do
		print (demonTarget, demonTarget.Character, demonTarget.Character.PrimaryPart, demonTarget.Character.PrimaryPart.Position)
		print (demon, demonTarget) -- None of these prints are nil
		
		local direction = (demonTarget.Character.PrimaryPart.Position - demon.PrimaryPart.Position)
		local distance = direction.Magnitude

		if distance <= configs.AttackRange.Value then coroutine.wrap(attack)(difficulty) end --[[ I don't 
know if this is way I wrote this coroutine.wrap stuff doesn't work, it seems to me it should but MoveTo 
still doesn't work when commenting out the rest of the while loop so this is not the reason I'm having 
this problem]]

		demon.Humanoid:MoveTo(demonTarget.Character.PrimaryPart.Position)
		--demon.Humanoid.MoveToFinished:Wait() 
		
		if demon.Humanoid.Health <= 0 then break end

	end

end

wait (10)
local demonClone = Demon:Clone()
demonClone.Parent = workspace

local giveBrain = coroutine.wrap(demonAI) 
giveBrain(demonClone)

I’m also quite certain that this has nothing to do with the 8 second cap there is on MoveTo since the problem is that MoveTo simply doesn’t work and not that it stops after a certain amount of time. I have also searched a lot on the forums but can’t find anything there, and I’m also aware that you have to manually add animations to the humanoid if you want it to animate.

2 Likes

Hello, correct me if I am wrong, but from what I understand your having issues mocking the player’s character. The best way to do this is to move the primary part.

The first way you can do this if you are just trying to move the player, is to change this property [player].character.HumanoidRootPart.Position = (the vector 3 value of where you are wanting to move to)

The other way is to set the CFrame. This can be done by using the SetPrimaryPartCFrame function. For example, [player].character:SetPrimaryPartCFrame(the CFrame value)

Shot in the dark: is any part of the model anchored?

21 Likes

B r u h.

I had checked for anchored parts before but missed one it seems. Thanks for the help man.

4 Likes

I am having this same issue but my parts are not anchored. Is there any other problem spots or is this just Roblox being funky

1 Like

While testing, drag the character up and see if it falls to verify that it’s not anchored. If it’s really not, feel free to make a separate post. Solved posts with lots of responses aren’t that likely to get follow-ups in my experience :+1:

2 Likes