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

Easier way to move models. Is there a way of making this script more efficient?

Asked by
RAYAN1565 691 Moderation Voter
5 years ago
Edited 5 years ago

Okay, so I've been scripting a basic script that sets properties of objects. I feel like there is an easier method of moving a model rather than moving each separate child of the model. Is there a way to do that? Writing scripts the way I do (as shown below) is taking an ample amount of time.

left = script.Parent.Left
right = script.Parent.Right
i = math.random(1,4)
print(i)

if i<=2 then
    leftClone = left:Clone()
    leftClone.Name = "leftClone"
    leftClone.Parent = game.Workspace.Obstacle_1
    print("Left is cloned!")
    print(leftClone.Parent)
    wait()
    leftClone.Part1.Anchored = true
    leftClone.Part2.Anchored = true
    leftClone.Wedge1.Anchored = true
    leftClone.Part1.Position = Vector3.new(-7.5, 27.93, -122.605)
    leftClone.Part2.Position = Vector3.new(-6.202, 52.194, -117.334)
    leftClone.Wedge1.Position = Vector3.new(-4.659, 52.211, -115.835)
    leftClone.Part1.Orientation = Vector3.new(10, 0, 90)
    leftClone.Part2.Orientation = Vector3.new(90, -45, 0)
    leftClone.Wedge1.Orientation = Vector3.new(0, -125, 0)
    wait()
    leftClone.Part1.Transparency = 0
    leftClone.Part2.Transparency = 0
    leftClone.Wedge1.Transparency = 0
    leftClone.Part1.CanCollide = true
    leftClone.Part2.CanCollide = true
    leftClone.Wedge1.CanCollide = true
    print("Left is visible!")
    wait()
    leftClone.Part1.onTouch_Death.Disabled = false  
    leftClone.Part2.onTouch_Death.Disabled = false  
    leftClone.Wedge1.onTouch_Death.Disabled = false 
elseif i>=3 then
    rightClone = right:Clone()
    rightClone.Name = "rightClone"
    rightClone.Parent = game.Workspace.Obstacle_1
    print("Right is cloned!")
    print(rightClone.Parent)
    wait()
    rightClone.Part1.Anchored = true
    rightClone.Part2.Anchored = true
    rightClone.Wedge1.Anchored = true
    rightClone.Part1.Position = Vector3.new(-0.53, 27.924, -122.765)
    rightClone.Part2.Position = Vector3.new(-1.722, 52.187, -117.204)
    rightClone.Wedge1.Position = Vector3.new(-3.269, 52.205, -115.755)
    rightClone.Part1.Orientation = Vector3.new(10, 0, 90)
    rightClone.Part2.Orientation = Vector3.new(90, 45, 0)
    rightClone.Wedge1.Orientation = Vector3.new(0, 125, 0)
    wait()
    rightClone.Part1.Transparency = 0
    rightClone.Part2.Transparency = 0
    rightClone.Wedge1.Transparency = 0
    rightClone.Part1.CanCollide = true
    rightClone.Part2.CanCollide = true
    rightClone.Wedge1.CanCollide = true
    print("Right is visible!")
    wait()
    rightClone.Part1.onTouch_Death.Disabled = false 
    rightClone.Part2.onTouch_Death.Disabled = false 
    rightClone.Wedge1.onTouch_Death.Disabled = false    
end

1 answer

Log in to vote
1
Answered by
INOOBE_YT 387 Moderation Voter
5 years ago

There is a function called :SetPrimaryPartCFrame(), this will do what you want to do, but it is also known to be inaccurate when done many times, you can still use it though. Before you use this function, you will need to set a primarypart. PrimaryPart is a property of a model and has to be a child of the model in order to be set. When it is set, just use the :SetPrimaryPartCFrame() method and in the parenthesis, just put the CFrame you want to move the model to. The model is moved based on the PrimaryPart's position.

1
So when I use the function, I would place the position I want to set the primary part in the parentheses of the function? :SetPrimaryPartCFrame(X, Y, Z) ? RAYAN1565 691 — 5y
0
The primary part is a property of models, so you set it how you would set the transparency of a part, etc... Example: Model.PrimaryPart = Model:FindFirstChild("Centre") INOOBE_YT 387 — 5y
0
:SetPrimaryPartCFrame() moves the primary part to the cframe that you put in the parentheses and the model moves with the primary part too INOOBE_YT 387 — 5y
1
It worked perfectly! Thanks so much for your answer! RAYAN1565 691 — 5y
Ad

Answer this question