How do I move a model using Vector3?

Hi. I’m trying to make a working elevator for my game, but I don’t know how to move the model using Vector3, since I guess its different from moving a regular part. Here’s my script:

Button = script.Parent
Elevator = game.Workspace.Elevator --The Elevator is the model

Button.ClickDetector.MouseClick:connect(function()
for i = .5,20,.1 do
game.Workspace.Elevator:MoveTo(90,i,50)
end
end)

My error is “Unable to cast double Vector3”. Sorry if I’m missing something obvious, I’m fairly new to scripting.

2 Likes

I believe you can weld models together so that they move together. You should use tween service to move the elevator though.

ex:

local TweenService = game:GetService("TweenService")
local seconds = 5
local elevator = game.Workspace.Elevator.PrimaryPart

local goal = {}
goal.Position = Vector3.new(10, 10, 0)
 
local tweenInfo = TweenInfo.new(seconds)
 
local tween = TweenService:Create(elevator, tweenInfo, goal)
 
tween:Play()

I suggest you format your code correctly.

Formatting
Use
```lua
--Code here
Closing ```
2 Likes

As far as I’m concerned you can’t move a model since all it is a group of a bunch of parts. You can either use a “in pairs” function, move them all one by one, or weld them using a WeldConstraint.

3 Likes

To add to this, you need to set the PrimaryPart property of the model to a part inside of it, and weld everything in the Elevator model to that part.

2 Likes

If I weld them does it become one part? That would be ideal for me because I already know how to move a part. If so can you tell me how to weld parts?

First you need to set the model’s primary part then create weld constraint’s for each part that weld to the primary part.

image

game.Workspace.Elevator:MoveTo(Vector3.new(90,i,50))

that’s what you meant probably.

You could just tween its primary part’s position too.

1 Like

It doesn’t become one part, but it attaches them together.

Alright cool. I think it will work though because if I stick all the parts together, and move up one part, all the ones connected to it will move up as well I believe. Thank you for your help.

1 Like