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.
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:
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…