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.
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.