Connecting all Train doors through a script

g’day.

I’ve got a train kit fully custom, I’m wondering how I could detect doors on other carriages and to link it to the main doors.

As an example, when a train opens their left doors, all doors on that side would be opened. I have all motors ready,just can’t figure out a simple but yet effective way rather than having more than 2 fori,v in pairs(carriage:getchildren()) sorta thing.

I have looked at previous but does not assist in this case. Here’s a few pictures, which contain the following:

  • How the trainkit looks in explorer
  • where the door scripts are contained

I’ve also tried using GetDescendants() but still isn’t effective enough.

Here’s the code i’ve tried to run to link the carriage doors together.

for i, des in pairs(train:GetDescendants()) do
	
	if des:IsA("Model") and des.Name == "Animations" then
		
		for index, d in pairs(des:GetChildren()) do
			if d.Name == "FrontLeft" or "MiddleLeft" or "RearLeft" then
				if d.Name == "FrontRight" or "MiddleRight" or "RearRight" then return end
				for i = 1, 75 do
					d.FrontLeft.L.A.Motor.C1 = d.FrontLeft.L.A.Motor.C1 * CFrame.new(0,0,0.035)
					d.FrontLeft.R.A.Motor.C1 = d.FrontLeft.R.A.Motor.C1 * CFrame.new(0,0,-.035)
					d.MiddleLeft.L.A.Motor.C1 = d.MiddleLeft.L.A.Motor.C1 * CFrame.new(0,0,0.035)
					d.MiddleLeft.R.A.Motor.C1 = d.MiddleLeft.R.A.Motor.C1 * CFrame.new(0,0,-.035)
					d.RearLeft.L.A.Motor.C1 = d.RearLeft.L.A.Motor.C1 * CFrame.new(0,0,0.035)
					d.RearLeft.R.A.Motor.C1 = d.RearLeft.R.A.Motor.C1 * CFrame.new(0,0,-.035)
					wait(0.0002)
				end
				
			end
			print(d)
			
			
			
		end
	end
end


each door model e.g. ‘MiddleLeft’ contains both Left and Right door which can be seen above.

Much appreciated.

If im understanding right, if you open a door on the left side of the train you want all the doors on the left side to open, and same thing for the right side. If this is the case I’m pretty sure you can use Collection Service to tag all of the doors on the right side as RightDoor and all the ones on the left as LeftDoor, then when you need those you can use the GetTagged method and find all doors that are tagged either LeftDoor or RightDoor.

1 Like

Alright, I’ll give that a try.

Alright cool, any luck on it??

Yeah there was some bugs here and there, but only just worked.