I'm wanting a train Model to move on it's track with TweenService. I've checked out https://devforum.roblox.com/t/any-way-to-tween-a-model-via-tweenservice/56845 and it did help a bit! I'm still struggling to get the "Main" Part to move to "NewPoint" 's position.

It seems like it's the 2nd to last line for the C1. Help greatly appreciated!

Updated as of 7:52 CST

local TweenService = game:GetService('TweenService')

local Nodes = workspace:WaitForChild('Nodes')
local Train = script.Parent

local Speed = 2
function GetTime(Distance, Speed)
	local Time = Distance / Speed
	return Time
end

local NewPoint = Nodes:WaitForChild('001') -- New selected point/node
local Distance = (Train.PrimaryPart.Position - NewPoint.Position).magnitude 
local Time = GetTime(Distance, Speed) -- Calculate the time

-- Welds 
local All = Train:GetChildren()
for A = 1,#All do
	if All[A]:IsA('BasePart') then
		if All[A].Name ~= "Main" then
			local NewWeld = Instance.new('Weld')
			NewWeld.Name = "Weld"
			NewWeld.Part0,NewWeld.Part1 = All[A],Train.Main
			NewWeld.C0 = All[A].CFrame:inverse()
			NewWeld.C1 = Train.Main.CFrame:inverse()
			NewWeld.Parent = Train.Main
		end
	end
end

local NewWeld = Instance.new("Motor6D")
NewWeld.Name = "Motor6D"
NewWeld.Part0,NewWeld.Part1 = Train.Main,NewPoint
NewWeld.C0 = Train.Main.CFrame:inverse()
NewWeld.C1 = NewPoint.CFrame:inverse()
NewWeld.Parent = NewPoint

---

local NewTweenInfoTable = TweenInfo.new(
	Time,
	Enum.EasingStyle.Linear,
	Enum.EasingDirection.Out, 
	0,
	false,
	0
)

game:GetService("TweenService"):Create(NewWeld,NewTweenInfoTable,{C1 = CFrame.new(NewPoint.Position)}):Play()
print(NewPoint.Position)

2 comments

1

The problem is your rigging. If you wanna move your model, you will have to rig your primary part with the other parts. Use a Motor6D. Here's a good plugin to help you with that: https://devforum.roblox.com/t/rigedit-create-and-edit-animation-rigs/70840 so TL;DR, it's not a problem with your script.

0

That did help a bit, I can't get the Model to move to the right part though!