Rollercoaster Tweening

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    Basically I’ve created the a roller coaster, and want it tweened.
  2. What is the issue? Include screenshots / videos if possible!
    The tween doesn’t make it look smooth, it’s kind of chopping; the script
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I’ve made the ServerScript and the module to return the Tween, But I wanted to see if theres any other options that might make it a bit smoother.

– Server Code.

local Currtime = .2
game.ReplicatedStorage.Power.Changed:Connect(function(p)
	if p == true then
		for i = 1,#Rails:GetChildren() do
			if Rails["P"..tostring(i)].Color == Color3.fromRGB(27, 42, 53) then
				Tween(Cart,Cart.Sel.CFrame,Rails["P"..tostring(i)].CFrame,TweenInfo.new(.5,Enum.EasingStyle.Linear,Enum.EasingDirection.In)):Play()
				Currtime = .5	
			elseif Rails["P"..tostring(i)].Color == Color3.fromRGB(163, 162, 165) then
				Tween(Cart,Cart.Sel.CFrame,Rails["P"..tostring(i)].CFrame,TweenInfo.new(.05,Enum.EasingStyle.Linear,Enum.EasingDirection.In)):Play()
				Currtime = .05
			end
			wait(Currtime)
			if game.ReplicatedStorage.Power.Value == false then
				break
			end
		end
	end
end)

– Module

local TweenService = game:GetService("TweenService")

return function(model,currentCFrame,goal,info)
	local value = Instance.new("CFrameValue")
	value.Value = currentCFrame
	local tween = TweenService:Create(value,info,{Value = goal})

	local connection
	connection = value:GetPropertyChangedSignal("Value"):Connect(function()
		if model.PrimaryPart then
			model:SetPrimaryPartCFrame(value.Value)
		else
			connection:Disconnect()
		end
	end)

	return tween
end

For a smooth rollercoaster, I do not suggest tweens at all, instead I suggest using Bézier Curves, You can create a series of points for your rollercoaster to go through, use it as a travelling line, when the rollercoaster starts you increase it’s speed and keep moving it every frame along with your line using RunService.Stepped

In the end of the Bézier Curves page you can see an example of what I’m talking about.

1 Like

I’m not to sure how I’d actually move the cart thought, That’s kind of where im stuck at.

Sorry, I’m still learning, so it’s kind of confusing

This How were the trains in Jailbreak done? [SOLVED] - #8 by Alexander_Ashford and some other train threads may help you. There was a really nice open source train I found on some post before but I can’t seem to find it.