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

Make a Group be copied from Lighting and placed according to where your player is?

Asked by
StoIid 364 Moderation Voter
8 years ago

I was wondering how to copy a model / Group from something like Lighting and put into the Workspace, at your players position. The group / model contains a bunch of parts, so I can't just have them all set to the players exact position otherwise they will all get jumbled up.

(Think of this. I want a house to spawn around my player, encapsulating it)

1 answer

Log in to vote
0
Answered by
legosweat 334 Moderation Voter
8 years ago

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 -- Gets the spawn part in workspace
local moveModel = game.Lighting.RandomModel:Clone() -- Get a copy of 'RandomModel' out of lighting
moveModel = game.Workspace -- put the RandomModel in Workspace
moveModel:SetPrimaryPartCFrame(CFrame.new(moveTo.Position) -- This will set the model's position to the SpawnPart in workspace.

Hope this gives you a good understanding of how to move a model!

0
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? StoIid 364 — 8y
0
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. legosweat 334 — 8y
0
I'm sorry but could you help me with that part? I'm having a trouble understanding. StoIid 364 — 8y
0
Do you have Skype? I can possibly share my screens to give you a better visual example. legosweat 334 — 8y
Ad

Answer this question