Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why doesn't this :MoveTo script move my character?

Asked by 5 years ago

This script is supposed to detect when you touch a part and when you do it will move you to a certain part. But it doesnt

local humanoid = game.Players.LocalPlayer.Character:WaitForChild("Humanoid")

script.Parent.Touched:Connect(function(touch)
humanoid:MoveTo(game.Workspace:FindFirstChild("DestinationStop"))
end)
0
Unrelated, but what's the parent of this localscript? If script.Parent isn't in character or tool than this script wouldn't execute. Consider changing script.Parent to a workspace reference or making this a server script Vulkarin 581 — 5y

3 answers

Log in to vote
3
Answered by
Isaque232 171
5 years ago

It's basically because MoveTo requires a Vector3 Value, and since you tried to put a object instead of it, It's won't work.

You'd need to get the part's position as It's a vector3 value, which can be done by simply changing

humanoid:MoveTo(game.Workspace:FindFirstChild("DestinationStop"))

to

humanoid:MoveTo(game.Workspace:FindFirstChild("DestinationStop").Position)

Hopefully that helps with your issue! Make sure to read read the MoveTo article as It'll for sure help you with some issues and questions you might have about it, make sure to accept if it solved your issue!

Ad
Log in to vote
1
Answered by
Ziffixture 6913 Moderation Voter Community Moderator
5 years ago
Edited 5 years ago

Your problem is being caused because you’ve passed the Model:MoveTo() method a Part. This won’t preform the anticipated movement as it expects a Vector3 of the Part. This is the Part’s raw position. You can use .p at the last parenthese to translate the Object to it’s Vector3.

Don’t use the Humanoid, this will make it walk with :MoveTo, use the Character instead as it is a method primarily use for Models.

local Part = script.Parent

Part.Touched:Connect(function(hit) --// Use this to get the Character that touched the Part
   local Part = workspace:FindFirstChild("DestinationStop")
   local Character = hit.Parent
   if (game:GetService("Players")[Character.Name]) then --// Reassurance
      Character:MoveTo(Part.p)
   end
end)

Hope this helps! If so, don’t forget to accept!

0
Humanoid:MoveTo() causes the player to walk, Character:MoveTo() causes them to teleport Vulkarin 581 — 5y
0
Nice syntax error on line 7 User#24403 69 — 5y
Log in to vote
-1
Answered by 5 years ago
Edited 5 years ago

You would need to get the part's position because MoveTo takes a Vector3 Value.

So like this:

local humanoid = game.Players.LocalPlayer.Character:WaitForChild("Humanoid")

script.Parent.Touched:Connect(function(touch)
    humanoid:MoveTo(game.Workspace:FindFirstChild("DestinationStop").Position)
end)

If there's any other issues, it's probably because of how you're handing when something touches your part.

0
Uh isn't that the exact same script he gave on his post? Isaque232 171 — 5y
0
Oops my bad. Sharkeedub 179 — 5y

Answer this question