The tween to slow for the my CFrame train system

Help with the tween, I’m trying to make a train on an cframe with a tween, and I synchronize the speed with the time of the tween, and the maximum speed that the train can reach is 32, although in the code it is 90, even if I divide the speed so that the animation is very fast, it doesn’t work and it always goes no more than 32, maybe maybe it’s the minimum values that a tween can take? I’d be glad if you could help me!

Video:


And here a piece of code(maxTime - max speed of train, current speed = 90):


local function moveToNode(wagonPart:BasePart, targetCFrame, speed)
	local newcframe = targetCFrame
	local distance = calculateDistance(wagonPart.Position, targetCFrame.Position)
	local maxTime = 90
	local time3 = maxTime - (distance / speed)

	if time3 < 0 then
		time3 = 0
	end
	
	if time3 == math.huge then
		newcframe = wagonPart.CFrame
		time3 = 0
	else
		newcframe = targetCFrame
	end

	--[[local tweenInfo = TweenInfo.new(time, Enum.EasingStyle.Linear)
		
		local tween = TweenService:Create(wagonPart, tweenInfo, {CFrame = newcframe})
		tween:Play()]]
	--print(90 - time3)
		
		TweenService:Create(wagonPart, TweenInfo.new(90 - time3,Enum.EasingStyle.Linear), {CFrame = newcframe}):Play()
		
			
	
end

You have a lot of variables here.

Where is your calculateDistance function. The calculation there could the the problem.

Right before your tween try this:

print("wagonPart.Position = ", wagonPart.Position, "  targetCFrame.Pos = ", targetCFrame.Position)  
print("time3 = ", time3)
print("newcframe = ", newcframe,  "  targetCFrame = ", targetCFrame) 

It will show you what your numbers will be calculated from and should help you figure out what’s happening.

So, i test the minimum speed for the tween, at 0 time of the tween the maximum speed of the train is 32, maybe the tween just have the minimum time for the animation

how about using the lerp?


That’s why I wanted you to see what all the prints were for the variables.
Screenshot all the variable prints in your output window when the distance is zero so we can see where the issue needs to be fixed.

So i found the sollution, the distance between train and movers are too low, but anyways thanks for help(anyways i try the print everything and got nothing special).

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.