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

Why can I only use 'MoveTo' to move zombies to their spawn points?

Asked by 7 years ago

So I have a zombie model and a part which is where the zombies spawn from. I have the script that clones and spawns the zombies but I'm confused even though I've fixed this. Why do I have to use MoveTo?

The script that is working is here:

zombie = game.Workspace.ServerStorage.Zombie
spawn = game.Workspace.ZombieSpawn

while true do
    local zombieCopy = zombie:Clone()
    zombieCopy.Parent = game.Workspace
    zombieCopy:MoveTo(spawn.Position)
    wait(5)
end

I'm confused about why I have to use zombieCopy:MoveTo(spawn.Position) and not zombieCopy.Position = spawn.Position.

I'm new to scripting so please understand me if I am missing something obvious.

1 answer

Log in to vote
0
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
7 years ago
Edited 7 years ago

The reason you have to use the MoveTo function, rather than being able to directly set a Position property is simple. Your zombie is a model! :D Models do not have the Position Property; therefore, you have to move it using a function.

Functions that can be applied to move models include:

I assume you already know how this is used, since you're using it.

model.PrimaryPart = model[1]
model:SetPrimaryPartCFrame(model:GetPrimaryPartCFrame() * CFrame.new(0,10,0))

This moves the center of the PrimaryPart to the given position. The model's PrimaryPart Property must be set prior to using the function. The code above would move the model 10 studs up.

model:TranslateBy(Vector3.new(0, 10, 0))

This shifts a model using a given offset. The code above would, again, move the model 10 studs up.


The only way to move a model entirely through code, without using a function, is to weld the entire model to one specific part inside it. After everything is welded you can set the CFrame Property of that specific part to move the entire model.

0
But what if I used a 'BodyPosition'? Inscendio 42 — 7y
0
That could work too. . It's a physics object. You can manipulate the properties of the BodyPositon to try and move the model. Goulstem 8144 — 7y
Ad

Answer this question