Issue with MoveTo

I am trying to create a cutscene triggered by the player that automatically makes their character move to a certain spot, but whenever I try to call :MoveTo on the players humanoid nothing happens.

This is the code I used in the script:

Trigger.Touched:Connect(function(Part)
	
	if Part.Parent:FindFirstChildWhichIsA("Humanoid") then
		Trigger.CanTouch = false
		local Humanoid = Part.Parent.Humanoid
		local HumanoidRootPart = Part.Parent.HumanoidRootPart
		local Player = Part.Parent
		
		Humanoid:MoveTo(Trigger.Part1.Position)
		Humanoid.MoveToFinished:Wait()
		task.wait(3)
		Humanoid:MoveTo(Trigger.Part2.Position)
		Humanoid.MoveToFinished:Wait()
		Trigger.CanTouch = true
		
	end
	
end)

The only thing I have thought of is that :MoveTo is not able to be called on a players humanoid, although I read through the entirety of the Humanoid documentation (might have missed something) and couldn’t find anything confirming that suspicion.

Any help or alternative solutions would be greatly appreciated!


Trigger.Touched:Connect(function(Part)
	
	if Part.Parent:FindFirstChildWhichIsA("Humanoid") then
		Trigger.CanTouch = false
		local Humanoid = Part.Parent.Humanoid
		local HumanoidRootPart = Part.Parent.HumanoidRootPart
		local Player = Part.Parent
		
		while task.wait(0.2) do Humanoid:MoveTo(Trigger.Part1.Position)
end
		Humanoid.MoveToFinished:Wait()
		task.wait(3)
		while task.wait(0.2) do
Humanoid:MoveTo(Trigger.Part2.Position)
end
		Humanoid.MoveToFinished:Wait()
		Trigger.CanTouch = true
		
	end
end)

You gotta run a loop for moveto to work.
I think.

This has half worked, but I’m marking it as solution as I can fix the second part. Thanks for the help!

1 Like

Facing issues with this, apologies.

The second MoveTo does not fire after the first because of the loop the first is wrapped in, causing the player to infinitely be moved back to Part1's position

1 Like

Perhaps try moving the MoveToFinish lines inside the loops and a break after.
Not too good at MoveTo, so I’m learning aswell.


Trigger.Touched:Connect(function(Part)
	
	if Part.Parent:FindFirstChildWhichIsA("Humanoid") then
		Trigger.CanTouch = false
		local Humanoid = Part.Parent.Humanoid
		local HumanoidRootPart = Part.Parent.HumanoidRootPart
		local Player = Part.Parent
		
		while task.wait(0.2) do Humanoid:MoveTo(Trigger.Part1.Position)
Humanoid.MoveToFinished:Wait()
break
end
		task.wait(3)
		while task.wait(0.2) do
Humanoid:MoveTo(Trigger.Part2.Position)
	Humanoid.MoveToFinished:Wait()
break

end
		Trigger.CanTouch = true
		
	end
end)

Try this maybe?

1 Like

I was just about to try this, after a few other ideas including the usage of break.

Thank you (so much) for the help! I really appreciate the time you have taken to write this out, and help me to come up with a solution. Have a great day or night

1 Like

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