RobloxScripterAI
Discord ↗
Link Copied to Clipboard
×
"Make a CFrame model move like a train"
-- server script (ServerScriptService) local train = game.Workspace.TrainModel local track = game.Workspace.Track local speed = 5 local function moveTrain() local waypoints = track:GetChildren() local currentIndex = 1 while true do local destination = waypoints[currentIndex].Position local distance = (train.PrimaryPart.Position - destination).Magnitude local moveDirection = (destination - train.PrimaryPart.Position).Unit train:SetPrimaryPartCFrame(CFrame.new(train.PrimaryPart.Position + moveDirection * speed, destination)) if (train.PrimaryPart.Position - destination).Magnitude < speed then currentIndex = currentIndex + 1 if currentIndex > #waypoints then currentIndex = 1 end end wait() end end moveTrain()