How to move a model with script?

hi, i was making a game when i noticed a problem. I wanted to make a script that changed the position of a model, but where I know the only way to move a model is to change the “Origin Position”, but I don’t know how to put in the script because has space and can’t put something in script with space.
Example script:

how to put the "Origin Position"
            V
game.Workspace.Model.??? = Vector3.new(x,y,z)`

I can’t put:

game.Workspace.Model.Origin Position = Vector3.new(x,y,z)

Because have space.
Does anyone know how to put the “Origin Position” in the script?

I started programming this month*.

Use Model | Roblox Creator Documentation to move the model to your vector3

2 Likes

@Dorthsky I will see if it works

The “MoveTo” doesn’t fit in my script

Try

game.Workspace.Model:MoveTo(Vector3.new(x,y,z)
1 Like

The only way of doing this is using moveto function but there are other ways, but the easiest is moveto. Do what dorthsky said,

game.workspace.Model:Moveto(Vector3.new(x,y,z)
1 Like

You can also use PivotTo or SetPrimaryPartCFrame if you’re trying to move the model with a CFrame value for example:

> game.workspace.Model:PivotTo(CFrame.new(0, 80, 0)
> game.workspace.Model:SetPrimaryPartCFrame (CFrame.new(0, 80, 0) -- would require a primary part`
3 Likes

I’m using the Script:

 local Parent = script.Parent
local Ball = workspace.ball

while true do task.wait()
	Parent:MoveTo(Vector3.new(
		Parent.Position.X,-- i need to put the Origin Position
		Ball.Position.Y,
		Parent.Position.Z-- i need to put the Origin Position
	))
end

I need to find out the Origin Position of the model anyway.

1 Like

Well, you cant use origin position

game.workspace.Part["Origin Position"] = vector3.new(0,0,0)

This is not possible using via lua code.

If you do the code I said, you will get the error

Origin Position is not a member of workspace.

You have to use cframe/Moveto functions.

If you are wanting to move the part to the origin. You could set the PrimaryPart property to a part inside the model or whatever.

Then run the following code

workspace.Part:SetPrimaryPartCFrame((Cframe.new(0,0,0))

or use the moveto function

Workspace.Part:MoveTo(Vector3.new(0,0,0))

1 Like

I believe the way you can get a model’s origin position is by Model:GetPivot() (which is a CFrame). So if you wanted a model’s position on the x-axis it would be Model:GetPivot().Position.X

1 Like

Try using model:PivotTo(your_Cframe)

1 Like
2 Likes