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

How to access all the parts in a model and change there position???

Asked by 3 years ago

So I want to duplicate a model of an R15 rig, and then I want to move the position of all the parts that can have their position moved. I started using an in pairs loop to get all the parts. But then I don't know what to do from there. I was thinking maybe doing every part that can be moved in the model and teleporting it, but that can't be efficient.

This is the script I'm thinking of:

--Sorry for the sloppy script
for i,v in pairs(Cv:GetChildren()) do

    if v.Name == "LeftFoot" then 
        v.Position = game.Workspace.EnemySpawn.Position 
    end

    if v.Name == "RightFoot" then 
        v.Position = game.Workspace.EnemySpawn.Position 
    end 

    if v.Name == "LeftLowerArm" then
         v.Position = game.Workspace.EnemySpawn.Position
    end

    if v.Name == "LeftUpperArm" then 
        v.Position = game.Workspace.EnemySpawn.Position 
    end 

    if v.Name == "RightLowerArm" then 
        v.Position = game.Workspace.EnemySpawn.Position 
    end 
    if v.Name == "RightUpperArm" then 
        v.Position = game.Workspace.EnemySpawn.Position 
    end 

    if v.Name == "LeftHand" then 
        v.Position = game.Workspace.EnemySpawn.Position 
    end 

    if v.Name == "RightHand" then 
        v.Position = game.Workspace.EnemySpawn.Position 
    end     

end

I was just wondering if the fine people of scripting helpers could help me find a more efficient way. Thank you for your time.

0
I would use Model:SetPrimaryPartCFrame() Leamir 3138 — 3y
0
Set a PrimaryPart on the model by clicking the property and then the part inside the model you want it to be the PrimaryPart. Then on the script use model:SetPrimaryPartCFrame(CFrame). It will change the CFrame of the primary part you have set and the other model parts will keep their position/orientation in relation to the primary part. Dfzoz 489 — 3y
0
Set a PrimaryPart on the model by clicking the property and then the part inside the model you want it to be the PrimaryPart. Then on the script use model:SetPrimaryPartCFrame(CFrame). It will change the CFrame of the primary part you have set and the other model parts will keep their position/orientation in relation to the primary part. Dfzoz 489 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago

If you just want to move the model you can move it by moving the PrimaryPart. If you don't have a PrimaryPart set, you can do it from the Properties editor in studio, or via a script (model.PrimaryPart = part).

Then you can do model:SetPrimaryPartCFrame(CFrame.new(x, y, z)) to give it a new Position or if you want to move it by x in a specific direction:

model:SetPrimaryPartCFrame(model:GetPrimaryPartCFrame() + Vector3.new(xOffset, yOffset, zOffset))

Hope this answered your question.

Ad

Answer this question