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(CFrame.new(Vector3.new(0,-0.17,0) +
workspace.Door.PrimaryPart.Position))
else
tb:Disconnect()
end
end)
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.
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.
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.