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.