Humanoid:Moveto changing the y position

I am making an npc that randomly moves from one part to another, but it changes the y position. I made sure that the parts that it is walking to are moved up so it wouldnt happen. Here is my script:

local hum = script.Parent.Humanoid

local CanMove = true

local function Finished()
hum.MoveToFinished:Connect(function() 
		task.wait(3)
		CanMove = true
	end)
	end

local function Move()
	
	local movetoparts = script.Parent.Parent.MoveTo:GetChildren()
	local randommoveto = movetoparts[math.random(1, #movetoparts)]
	
	CanMove = false
	
	hum:MoveTo(randommoveto.Position)
	
end

while true do
	if CanMove == true then
		Move()
	else
		Finished()
	end
	task.wait(1)
end






1 Like

You can create a new vector3 using the randommoveto position but leave out the Y to make sure humanoid isn’t moved on the Y axis
replace “hum:MoveTo(randommoveto.Position)” with this line below

hum:MoveTo(Vector3.new(randommoveto.Position.X, 0, randommoveto.Position.Z))

That doesn’t work, I have no clue why. There are no scripts changing anything else. It still is in the ground when it moves. No matter what I change the y value to, nothing happens.

Hi!

Could the issue be that your HipHeight of the Humanoid is wrong?

1 Like

ok i think u wanna make the npc moves a part randomly and they stay in this part for 3 seconds and then continue the cycle after 1 second, so try using this code:

local hum = script.Parent.Humanoid

local function Move()
	
	local movetoparts = script.Parent.Parent.MoveTo:GetChildren()
	local randommoveto = movetoparts[math.random(1, #movetoparts)]
	
	hum:MoveTo(randommoveto.Position)
        hum.MoveToFinished:Wait()
        task.wait(3)
end

while true do
	Move()
	task.wait(1)
end

Sorry! I was gone for a while. This was the problem, thanks!