Best way to make a multi parts door move?

My question is simple: What is the best way to make a multi parts door (around 20 parts) move? Right now I am using a heartbeat loop which moves the cframe of the primarypart. Although this works, it can also be laggy. This is an example of the code i use:

local a1 = 0
local a = 60
tb = RunService.Heartbeat:connect(function()
  if a1 < a then
    a1 = a1 + 1		        			 
    workspace.Door:SetPrimaryPartCFrame(,-0.17,0) + 

You can try welding everything to one main part and unanchoring it but anchoring the part.

1 Like

You can also use a constraint instead of a cframe loop. You also do not need to use a connection like that because you can do something like

for i=0,60 do

or use the tween service like below

1 Like

If you weld them all, you should be able to tween the CFrame of the main part using TweenService and have all the other parts move. That should make it smoother.

1 Like

Parts relative CFrames to each may drift and deviate if you use SetPrimaryPartCFrame too many times. I’d suggest defining offset cframes from a primary part, or welding the parts to a primary part.

Are all the parts in the door CanCollide? If they are, the poor performance might be caused by having to recalculate physics data each time the door moves. You could try having one CanCollide part to represent the collision box of the door and make it so the rest of the parts don’t need to have collisions.

1 Like

Don’t use SetPrimaryPartCFrame constantly on an object

Using a union to combine all the parts into one would probably help the performance. It’ll probably greatly simplify the collision mesh, and combine many of the properties that the physics engine worries about (like their CFrame) into one.

Honestly I just use a hinge constraint and weld everything to a singular “Collision” door piece. Then just have hit detecting part extending a few studs out que the servo motors in the hinge to open up.

I wouldn’t suggest any of these replies. the best thing to do is to tween a CFrame value to what you want while looping SetPrimaryPartCFrame to the CFrameValue’s value.

It’s what my placement system uses for entire models.