This is somewhat of a simple task.
Some things you need to understand is the clone() event which would copy the model, moving a model to a certain position, in this case, cloning the model from lighting and putting into workspace at the players position.
There are 2 different ways to do this;
- MoveTo
- SetPrimaryPartCFrame
In my example, I'll use the SetPrimaryPartCFrame event instead of the MoveTo due to proficiency.
Before we get into that, you need to know a little about the 'PrimaryPart' of the model.
The PrimaryPart is the part which is positioned with the SetPrimaryPartCFrame(or MoveTo).
Note when assigning the PrimaryPart that the part must be a descendant of the Model. If not, the PrimaryPart will be set to nil.
To set the primary part of the model, click on the model, and in the properties window, click on the empty box next to the name of 'PrimaryPart", then view your model in studio, and click the part to set it as the PrimaryPart. After this, you may notice there is not a blank box next to "PrimaryPart", but the name of the part you've clicked. If it is not there, then you're doing it wrong! (Don't select it from the Explorer window.)
Now, we can get into SetPrimaryPartCFrame.
This is the CFrame of the PrimaryPart. All other parts in the model will also be moved and will maintain their orientation and offset respective to the PrimaryPart. This function will throw an error if no PrimaryPart exists for the Model.
Example of how this could be used:
local moveTo = game.Workspace.SpawnPart
local moveModel = game.Lighting.RandomModel:Clone()
moveModel = game.Workspace
moveModel:SetPrimaryPartCFrame(CFrame.new(moveTo.Position)
Hope this gives you a good understanding of how to move a model!
4 comments
Thank you! But lets say i delete it and i move my player then run the script again, will the model be placed to where my player is?
Well, you'll need to get the player again when the function is called. So put the variable when you get the player inside of the function, so it gets the player in its position evertime the function is called.
I'm sorry but could you help me with that part? I'm having a trouble understanding.
Do you have Skype? I can possibly share my screens to give you a better visual example.