Problem with :MoveTo

Hello, Roblox community! Today I have a problem with :MoveTo, Here is my script (It’s a local script in the PlayerGui) :

wait(10)
game.Players.LocalPlayer.Character:MoveTo(game.Workspace.Example.MoveTo.Position)

MoveTo = a part

The Output : attempt to index function with ‘Position’

Use this code

wait(10)
game.Players.LocalPlayer.Character.PrimaryPart:MoveTo(game.Workspace.Example.MoveTo.Position)

The character is just a model so you can’t move it via a script.
You need to move the model’s PrimaryPart

I have the same problem with the PrimaryPart :confused:
attempt to index function with ‘Position’

Is Example a model?

If so, what lua is doing is actually accessing the MoveTo method (the same one you’re firing on the character!) – It is possible to access functions with . instead of : (but this causes adverse effects and you shouldn’t do it.

Try altering your code to this:
game.Players.LocalPlayer.Character:MoveTo(game.Workspace.Example:FindFirstChild("MoveTo").Position)

Placing the object in ["brackets and quotes"] tells it to look for an object with that name. (Edit: This is false.)

It also allows you to get objects that have spaces or periods in their name.

1 Like

is MoveTo a child?
Also is MoveTo a model?

I have the same problem : attempt to index function with ‘Position’

I said MoveTo is a part [30Char]

Then change it to :FindFirstChild("MoveTo"). The bracket method actually accesses functions as well. My mistake. Hadn’t realized that.

2 Likes

put that local script inside startercharacterscripts

Thank you very much! You’re a great person!

2 Likes