Background moving train

In Toolbox i repeat, there are also CFrame scripts for models which are nice. But they are using a loop and cannot be stopped unless you make another script trying to fight that force. I need to explain more about what im talking?

Also, about only be moved in the client, i think you can use LocalScripts and that stuff.

You use TweenService. So first you would make a train model and set a primary part, then you just have to insert this script:

local TS = game:GetService("TweenService")
local TI = TweenInfo.new(time to go from one side to another, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut)

local Train = --reference the train

TS:Create(train.PrimaryPart, TI, {Position = Vector3.new(ending position))
1 Like

It is okay for it to only go straight line. I just don’ t know how to write a script and where should the parts name and where should put the script and the train.

The script above seems perfect for your question.
You only have to reference the time and the train model inside the workspace.

For example: if your train was named “Train” and you placed it in workspace, you would access it like

local TS = game:GetService("TweenService")
local TI = TweenInfo.new(10,  Enum.EasingStyle.Linear, Enum.EasingDirection.InOut)

local Train = workspace.Train

TS:Create(Train.PrimaryPart, TI, {Position = Vector3.new(ending position));

Used the script from above assuming the train is in workspace named “Train”, moving in 10 seconds from the start to end position.

So, where should I place the script?
Should I change the parts name?

Should I leave my train model here for you guys to figure out how should it work?

Excuse me, but how can I set a primary part? (Yes I’m stupid and sorry about it)
P.S Here is a pic of a similar train model that I am working on, not sure can it help you or not.

Hi. You can manually choose the primary part by setting the model’s PrimaryPart property. Just click the model, press the PrimaryPart value (nil by default) and select a part parented to the train.

If you want to use a script, something like this would work:
workspace.Train.PrimaryPart = workspace.Train:FindFirstChild("Part")

1 Like

Just so you know, doing this will not work, because setting the primary part’s position only changes the primary part’s position.

You should to use this method (albeit outdated), because it would take significantly longer to rig the train.

@Edison20020216, here’s some food for thought.

local TweenService = game:GetService("TweenService")

local CFrameValue = Instance.new("CFrameValue")
CFrameValue.Value = Train:GetPrimaryPartCFrame()

local tween = TweenService:CreateTween(CFrameValue, TweenInfo.new(10, Enum.EasingStyle.Linear), {Value = endCFrame}) -- make sure to define endCFrame

CFrameValue.Changed:Connect(function()
	Train:SetPrimaryPartCFrame(CFrameValue.Value)
end)

tween:Play()

tween.Completed:Wait()
CFrameValue:Destroy() -- does garbage collection for changed on destroy

If you don’t feel comfortable using this method, then you can use the more updated version of @PostApproval’s model tweening method:

4 Likes

It is so complicated, my mind is hurt while reading this, I will see if I understand how it work when I get back on to the studio later. Thank you for your help.

1 Like

To select the primarypart do this:

1- Go to the properties of the model of your train.
2- Click on PrimaryPart, if it has already then leave it like that.
3- Go to explorer and click a part, to select the primarypart, i recommend you the front part.

That’s it.

1 Like

You dont need primary part for this, you need any part, welded to all others

Incorrect Answer

@mistr88 Nope, welds break whenever you apply positional changes or cframe changes. That doesn’t change anything.

Welds do NOT break whenever you apply positional changes as long as they’re WeldConstraints. ManualWelds do break when that happens.

It’s not. Basically, it tweens the CFrame value, and when it’s changed it sets the primary part’s cframe. Nothing complicated at all.

Really, i made background car system, by moving welded model
and this is also based on moving welded models

No, no, noooooooo, this is looping every child of it, i have expirence with this.

I already suggested the resource. It takes quites some time to rig an entire train. That’s why I suggested the old one first.

That’s how it’s supposed to work. It works relative to the PrimaryPart, yes it has bugs, thus why I suggested the other resource.

1 Like

You can actually move and rotate a model using CFrame even if there are WeldConstraints in its parts. An alternative way to SetPrimaryPartCFrame would be to directly change the CFrame of a random part of the model, which would have to be anchored and welded to the other parts (welding is not disabled).

Yes, that will work. However, using normal welds will in fact break it.

I completely forgot about weld constraints, and I should’ve remembered to tell him to anchor it. All of this stuff should work if this is the case.

As a sidenote, I typically don’t use WeldConstraints, because I’m used to using the typical Welds. I’m also worried that it won’t break joints when an explosion hits it like a normal weld.

2 Likes
4 Likes