Hello, I can't get this to work, I am trying to make (the red part) find the order of the track parts(Orange Part) and Cframe through them in Order. This is for a rollercoaster so it would be able cframe through each part.
Thanks!
Image: http://prntscr.com/n6y0dq
Code:
local function StartCoaster(Coaster,RailModel)
local Rails = RailModel:GetChildren()
--sort rails table from lowest number name to highest number name:
table.sort(Rails,function(a,b)
return tonumber(a.Name) < tonumber(b.Name)
end)
for RailNum,Rail in pairs(Rails) do --go through ordered rails
for _,Segment in pairs(Coaster:GetChildren()) do
local GoalRail = Rails[RailNum + tonumber(Segment.Name)]
local Tween = game:GetService("TweenService"):Create(Segment, GoalRail.CFrame)
Tween:Play()(Segment, GoalRail.CFrame) --handle tweening here
end
wait(1) --change to time taken for tween
end
end
StartCoaster(workspace.Coaster, workspace.RailParts)
