Humanoid:MoveTo() will not work

Hey developers.

Before I begin, I would like to mention that yes, I have searched through similar posts, and no, none of them were helpful.

Anywho, I’m having some struggles with a script that makes a humanoid move.

local wt = script.WalkType
local char = script.Parent
local hrp = char.HumanoidRootPart
local hum = char.Humanoid

task.wait(2)

local function walkTick()
	if wt.Value == "Wander" then
		local mv = Vector3.new(hrp.Position.X + math.random(-40,40), 0, hrp.Position.Z + math.random(-40,40))
		
		if mv == Vector3.new(hrp.Position.X, 0, hrp.Position.Z) then
			return 0
		end
		
		print("oh we movin")
		
		script.Parent.Humanoid:MoveTo(mv)
		task.wait()
		
		script.Parent.Humanoid.MoveToFinished:Wait()
		
		task.wait(math.random(1,10))
		
		return {}
	end
end

while task.wait() do
	local s, e = pcall(function()
		local call = walkTick()
	end)
	
	if not s then
		warn(e)
	end
end

This here is the script. The value mentioned on lines 1 & 9 is always set to “Wander” without change (I plan to have some NPCs have different movement behaviors).

Here’s what’s even stranger though: the script works sometimes.

5/6 of the time, the script works just fine.
On the off 1/6 of the time, the script “works”. Sure, it prints “oh we movin” as mentioned on line 16, but it doesn’t actually move the humanoid.

I’ve tried several things:

Did you make sure all of the parts were unanchored?
Yes.

Did you look at tutorials?
Sure did (none of them were helpful).

Did you check that the Vector3 is not the same as the current humanoid root part’s position?
dude.

So yea. Any help would be much appreciated. I am very confused by this issue.

Not going to help you any but I did paste your code into a script and run it. It moved the R6 Rig 100% of the time. I added a print after the wait to say it was done moving and it was moving every time it said it was.

1 Like

I’m using an R15 rig. Maybe that’s the issue?

Not for me I just tried that as well and still moves 100%.

1 Like

Well, as you can see here, it does not work for me.

I really have no idea what to do about this.

I am doing it in a simple baseplate so that might be part of it as well. You could maybe pull your character into a simple baseplate and try it there and also do an R15 rig to see if it works in that environment.

1 Like

Yea, it works, but this begs the question: why doesn’t it work in the base game?

The only things in the base game are a few sounds in workspace, another NPC, some parts, and a few remote events in ReplicatedStorage.
It’s basically a baseplate with extra steps.

You did have a couple errors pop up. I’d make sure you eliminate those and try running it when you have no errors popping up.

1 Like

The errors in the video I presented earlier were in a completely unrelated script. It doesn’t break the script in any way, so frankly I can’t be bothered to fix it.

Hello! This is because you are using MoveTo on a humanoid, MoveTo can and should primarily be used on Models!

local wt = script.WalkType
local char = script.Parent
local hrp = char.HumanoidRootPart
local hum = char.Humanoid

task.wait(2)

local function walkTick()
	if wt.Value == "Wander" then
		local mv = Vector3.new(hrp.Position.X + math.random(-40,40), 0, hrp.Position.Z + math.random(-40,40))
		
		if mv == Vector3.new(hrp.Position.X, 0, hrp.Position.Z) then
			return 0
		end
		
		print("oh we movin")
		
		script.Parent:MoveTo(mv)
		
		task.wait(math.random(1,10))
		
		return {}
	end
end

while task.wait() do
	local s, e = pcall(function()
		local call = walkTick()
	end)
	
	if not s then
		warn(e)
	end
end
1 Like

You’re technically correct, but this makes the humanoid teleport, not walk.

I want the humanoid to walk.

Apologies for the misunderstanding, without more context, there doesn’t seem to be much wrong from first glance, I do know most player input will actually cancel the :MoveTo(), in addition do make sure everything is actually there using print() statements.

1 Like

Another script I had in the humanoid was what was breaking it. After I fixed the other script, the movement script worked just fine.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.