Humanoid:MoveTo() is being odd

Hey everyone!

I’m currently trying to make a Tree-Mining system. I’ve coded this before but I want to make it more efficient and upgrade it. Everything is working great, except for the fact that MoveTo() is moving me to random locations.

Here’s my script:

local tree = script.Parent.Parent.Parent.Parent

script.Parent.ClickDetector.MouseHoverEnter:connect(function(player)
	game.ReplicatedStorage.Trees.CreateSelectionBox:FireClient(player, tree)
end)

script.Parent.ClickDetector.MouseHoverLeave:connect(function(player)
	game.ReplicatedStorage.Trees.RemoveSelectionBox:FireClient(player, tree)
end)

script.Parent.ClickDetector.MouseClick:Connect(function(player)
	player.Character.Humanoid:MoveTo(Vector3.new(tree.Wood.Stump.Position + Vector3.new(-3,0,0)), tree.Wood.Stump)
	print("Moved.")
end)

Basically, I want my player to move to the Tree Stump’s position, just 3 studs away on the X axis. The position I get the player moving to, though, is really far away. I’ve even tried copying and pasting the tree stump’s position, manually adding 3, and putting the new Vector3 value into my player’s Humanoid.WalkToPosition property, but it still doesn’t work.

Any help is greatly appreciated. Thanks! :slight_smile:

1 Like

Is it moving to Random Parts of the map, or a specific place everytime? At the top you said random, and then at the bottom you said really far. Just trying to get a picture.

I’m pretty sure it’s because you are making an unnecessary Vector3. Simply add the two positions, you do not need to make a new Vector3 with the result. This is what it should look like:

player.Character.Humanoid:MoveTo(tree.Wood.Stump.Position + Vector3.new(-3,0,0), tree.Wood.Stump)
1 Like

This is because by supplying the second arg (part), you are supposed to add a local vector, not a world pos vector.

You should be able to just remove the tree.Wood.Stump.Position + from your position argument, and it should work. If that doesn’t work, you can remove the part argument.

The second argument sets the Humanoid’s WalkToPart property, which means the WalkToPos property gets transformed relative to the part. If you’re adding the stump’s position to that, you’re telling it to move very far away relative to the tree…

Documentation

4 Likes

It goes to the same spot every time, but it isn’t the place I want. Sorry for the confusion.

Oh! I think that is the problem. I’m going to school now but I’ll test it at home. Thanks!

It worked! Thanks again! under30characters