Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Help with :MoveTo() and Vector3 values. [?]

I have this one line of code that moves a model, here it is.

game.Workspace.Paper:MoveTo(game.Workspace.Paper.MP.Position.X,
game.Workspace.Paper.MP.Position.Y + 2, game.Workspace.Paper.MP.Position.Z)

Even though it shows two lines, they are actually one.

The error is: Unable to cast double to Vector3

1 answer

The MoveTo function's first and only argument must be the Vector3 position you're trying to locate. Your code however, is the equivalent to saying something like this:

model:MoveTo(0,0,0) -- "0,0,0" being whatever coordinates you have above

Which is invalid. A valid example, would be taking this tuple and passing it to Vector3.new, like this:

model:MoveTo(Vector3.new(0,0,0)) -- Now putting our coordinates in a Vector3 value, which is then passed to MoveTo.

Solution

So to fix your problem, simply put the coordinates in a Vector3 value, like so:

local paper = workspace.Paper
local obj = paper.MP

paper:MoveTo(Vector3.new(obj.Position.X,obj.Position.Y+2,obj.Position.Z))

Alternative solution?

Just for the record, instead of continuously repeating "object.Position.Coordinate", you could add the initial position vector, with the new vector, like this:

local paper = workspace.Paper
local obj = paper.MP

paper:MoveTo(obj.Position+Vector3.new(0,2,0)) -- Works just the same.

Hope this helped, let me know if you have any questions.

This discussion is preserved as it was. New answers, comments, and votes are closed.