How do you make a part perfectly connect to another currently tweening part?

I’m basically making a game where you’re in an endless train trip, but instead of making the train move, I’m making tunnels generate and constantly tween/delete/spawn, I have achieved the generation, but now the problem is when I spawn a new tunnel in front of the previous tunnel, it sometimes spawns leaving a gap instead of being perfectly attached to the other one. Here’s a video to show what I mean :

I have checked for answers on forums but they don’t match with what im trying to achieve, what should I use to perfectly connect the spawning tunnels to the previous ones while they’re being tweened ? And how would it work ?

Short answer: You’ll need to sync manually

This is because weld constraints only work on objects affected by physics. So if you want to have them sync automatically, use a physics constraint.

Some psuedo code for that:

local direction = Vector3.new(1, 0, 0) — The direction that the next tunnel will generate. Must be 1 or -1
local rotAngle = Vector3.new(math.rad(15), 0, 0) — The angle the next tunnel will be rotated.
local tunnelComp = …

local function get_cf(oldPos)
  return CFrame.new(oldPos + (direction * tunnelComp.Size)) * CFrame.Angles(rotAngle.X, rotAngle.Y, rotAngle.Z)
end

But how and which one ? If I make the tunnel moves based on physics couldn’t it be floppy ? Which one could I use to make them achieve a constant speed without bumping each other and perfectly connected with each other ? Also I’m not using weld constraint, tho I have tried but as you stated it doesnt work either. I’m currently setting the CFRame of new spawning tracks to be perfectly aligned with the previous one, but because of server delay and processing time, it makes the tween of the new track delay a little bit based on server proccess time

Well the code I provided you should place the next tunnel part correctly if you use it right.

It is already CFramed to be perfectly connected to its previous one thought, it’s bc the server delay makes the the new spawned track delay the tween and the delay of the tween is based on server proccess time speed

Actually you can use the jigsaw method. Just put 2 attachments inside a tunnel component one for attaching other tunnel parts and another one for connecting it to the previous one. To attach a tunnel part, find the previous one and attach the new one to the connection attachments WorldPosition.

Oh. Then maybe start the tween only when the new component is in position.

you should probably ditch the tweening and use a heartbeat loop instead, then you can use the delta time to compensate for frameloss.

runservice.Heartbeat:connect(function(delta)
    print(1 * 60 * delta) -- this will compensate the number 1 and make it larger or smaller based on the delta time
end)

I don’t think he means frame loss by “delay” in this case.

Can’t you just weld the parts together?

You can weld the parts together and instead of tweening use lerping instead (since lerp does move welded parts).

Doesn’t work while it’s tweening

I tried but it doesn’t give out a smooth result

You could try making multiple separate leaps instead of one that goes the entire route I guess?

It’s what it’s currently doing, there’s not just 1 that goes and the rest follows, each tunnels are independent and they get removed at a specific position, but it’s okay i fixed the issue by canceling each tweens once a new tunnel spawns and tweening everything back right away, althought im sure there’s a better approach but so far the rest didnt work

Nvm it still sometimes leaves gaps, more rarely but still happens, I really don’t know how to achieve this

For me it does. I have a working door where all the parts of the doors are welded to a hinge and that hinge rotates with a tween.

Yea because yours is already pre-set, if you look into the video I attached above, the tunnels are constantly tweening, and what I’m trying to achieve is connect a part to another part that is ALREADY TWEENING

Also I don’t know how i’d go about using welds because I need at least 1 part to tween, but they get deleted once they reach a point, so once the tunnel that tweens while everything else is welded to it gets destroyed, everything will be destroyed, unless i kind of use some sort of advanced way to detect all the welds, then delete them and reconnect everything but it will be a huge mess

For anybody that has the same issue :

I managed to fix it by making it so only the first tunnel tweens, then I use weld constraints to weld the other tunnels to the tunnel in front. Once the front tunnel despawns, I add 1 task.wait(), then weld all the other tunnels to the new in-front tunnel again.

(You can’t weld the tunnels while it’s tweening, so if you want a different approach make sure you cancel the tween of the object, then in that meantime weld the other object to it, then tween it again)