How would go about making a train tween. Basically, I want to make a train tween along this path, however, I need it to play multiple tweens for it to follow a path as show in the image below
However, there would be another train, let say spawn at the part which it needs to play Tween2 first instead of tween1, unlike the first train, meaning i would have to change the tween sequence too
It takes a little more tasks to put all the train scripts together, but the idea of shortening the code section of the tween is to use the following code.
--You need to define more at least TRname and Tweens and so on
local startnum = 1
local allpathnum = 8
local function defineTRName()
while true do
if TRName == "Train" .. startnum then
break
else
startnum += 1
end
end
end
local function tweenTrains()
local currentnum = startnum
while true do
local currenttween = Tween .. currentnum
currenttween:Play()
currenttween.Completed:Wait()
if currentnum == allpathnum then
currentnum = 1
else
currentnum += 1
end
if currentnum == startnum then
break
end
end
end
defineTRName()
tweenTrains()
I will only explain tweenTrain() since the rest is about definitions. tween1,tween2,… is TweenX(X=currentnum|first currentnum is strartnum as Train number). What we want to do is to tween and then tween the next number of tweeners, so after tweenX, we can add 1 to X (if X=8, we set X=1). Then when the train goes around and X becomes Train number (=startnum), you are done. This is what tweenTrain() does.
If you don’t know what you want to do and how you want to make it a function, write a flowchart. It is a bit tedious but should be useful!
the picture below is a flowchart of tweenTrain().
draft→generalize→functionize
Y is currentnum in the code.