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

How do I move a Model using scripts?

Asked by
Loot_O 42
4 years ago

Alright, so I'm trying to move models around for my game. But when I try to move a model, I get an error. Here are the things I tried:

local pineTree = workspace.PineTree

pineTree.Position = Vector3.new(10, 10, 10)

On this code above, it says that Position is not a valid member of the Model; this means the script is trying to find a child named "Position" and since it didn't find the child with that name, it gives me an error.

local pineTree = workspace.PineTree

for i, v in ipairs(pineTree:GetChildren()) do
    if v:IsA("Part") then
        v.Position = Vector3.new(10, 10, 10)
    end
    wait()
end

On this code above, it can move the parts; but not the correct way. It puts all parts in 1 place, and it looks bad. Here is what it looks like: Link. So in conclusion, the 2 ways I've tried doesn't work, and I want to know how to move a model using scripts like this.

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 3 years ago

If you want to move a model through a script you could use [Modelname]:MoveTo(Vector3.new(position))

Example:

--ServerScript in workspace
local model = workspace:WaitForChild('Drooling Zombie') --Our model
model:MoveTo(Vector3.new(31.4, 0.5, -32.8)) --New position
0
ok thanks man Loot_O 42 — 4y
Ad

Answer this question