Tween speed won't increase past a certain point

I’m working on making a moving train, and everything seems to be working just fine, except that it won’t go fast enough. I’m using this method to move the train since the track isn’t just a straight line.

The way the method I’m using works is that it has a train track and every wooden plank in the train tracks has a node attachment and a value that provides the time for the tween to get the train to the plank. Changing the time value changes the time that the tween takes as expected, but I want the train to go at a relatively high speed, and once I set the time value to around 1 or lower it stops making the train go faster.

The planks are 10 studs apart, I want it to take the train about half a second or less to get from one to the next, so the train is going less than half the speed I want it to.

Is this due to a limit in the tween service? I couldn’t find anything that said there was a limit to the speed you can tween something. Or should I be using a different method? I’m new to scripting so I don’t know if I’m even doing this the best way possible, or if there’s some stupid mistake I’m making. Any help is appreciated!

Here’s the code I have so far, it works perfectly except for the speed thing!


wait(1)

local rails = script.Parent.Parent.Parent.Parent:WaitForChild("Track")
local main = script.Parent:WaitForChild("Primary")
local ts = game:GetService("TweenService")

local nodes = {}

for i,v in pairs(rails:GetDescendants()) do
	if v:IsA("Attachment") and v.Name == "Node" then
		table.insert(nodes, v)
	end
end

	for i,v in pairs(nodes) do
		local goal = {}
		goal.CFrame = v.Parent.CFrame + Vector3.new(0, .309, 0) 
		ts:Create(main, TweenInfo.new(v.Parent.Time.Value,  Enum.EasingStyle.Linear, Enum.EasingDirection.Out), goal):Play()
		wait(v.Parent.Time.Value)
	end

There isn’t a limit.

There are a few things that I think might be causing this problem:

  • v.Parent.Time.Value is too high
  • Your constraint connecting the cart to the tweened part isn’t strong enough

Just a side note about your code:

ts:Create(main, TweenInfo.new(v.Parent.Time.Value,  Enum.EasingStyle.Linear, Enum.EasingDirection.Out), goal):Play()
wait(v.Parent.Time.Value)

Instead, do this:

local tween = ts:Create(main, TweenInfo.new(v.Parent.Time.Value,  Enum.EasingStyle.Linear, Enum.EasingDirection.Out), goal):Play()
tween.Completed:Wait()

Using events is more accurate and consistent :+1:

Thank you! That didn’t occur to me, and now I realize that the part being tweened seems to be going the correct speed, but the model attached to it is lagging behind. This does seem to be something to do with the constraint, but I can’t seem to figure out how to fix it, could you tell me how to do that?

As for code help on the tween, thank you! I’ll fix that

1 Like

It depends what kind of constraint you used. Which constraint are you using?

Edit:
It’s probably named something like MaxForce (for SpringContraints and BodyPositions at least).
Edit 2:
I noticed on the reply you linked they used an AlignPosition. You’ll probably want to up the MaxForce and Responsiveness.

Do MaxForce and Responsiveness need to be changed in a script? I don’t see them in the properties window (sorry if I’m being dumb lol)

1 Like

Oh, that’s my bad. AlignPositions have a few different modes, and each mode uses different settings. Could you send a picture of the properties in your window?

Edit:
I guess that means you have RigidityEnabled set to true. In theory that should make your cart use maxed out MaxForce and Responsiveness. I’m not sure what the problem is, maybe send a video?

Source

When RigidityEnabled is true, then the physics solver will react as quickly as possible to move the attachments together. This is the same scale of force used to connect other constraints, such as hinges when their attachments are separated.

When RigidityEnabled is false, then the force will be determined by the AlignPosition.MaxForce, AlignPosition.MaxVelocity, and AlignPosition.Responsiveness. MaxForce and MaxVelocity are caps to the force and velocities respectively. The actual scale of the force is determined by the Responsiveness. The mechanism for responsiveness is a little complicated, but put simply the higher the responsiveness, the quicker the constraint will try to reach its goal.


Does this help at all? As you can see the model is lagging behind the tweened part (enlarged to show what’s happening)

1 Like

Try disabling RigidityEnabled and setting MaxForce and Responsiveness to math.max (I believe you can type “inf” to get math.max) (or if RigidityEnabled is false try turning it on).

The only other thing I can think of is making some of the parts Massless, though you shouldn’t need to do that. math.max is HUGE.

1 Like

Thank you so much! That fixed it, MaxForce wasn’t the maximum number and setting it higher made it work! Thank you!

1 Like