How would I make a working 0-100% throttle system that will be for a train?

Currently I have a train which is a manual train game, I am currently attempting to make a 0-100% throttle, similar system to PTFS in Roblox. How it works is that if the throttle is at 100%, the train will go full speed, while at 50%, it’ll go 50% of its intended speed. How would I achieve that?

Do you use hinge constraints for motors? If you do, you can just set the angular speed of the motors to this.

hingeConstraint.AngularVelocity = Speed * Percent

Edit : If you don’t know how to use constraints or have never used them, try checking these tutorials out.

you can use a variable to store the current throttle value, and then use that value to determine the speed of the train.

There is a variable that determines the throttle value as of right now, but how would I achieve so the train would go the speed of the speed that is needed to reach?

I am currently using BodyThrust.

Set the speed of the train based on the throttle value then calculate the speed based on the throttle value then you set the speed of the train to the calculated value & you set the initial speed of the train based on the current throttle value, is there UIs buttons to control it? Just curious.

UI Buttons are only for mobile support of controlling, otherwise on PC, it is W and S or UP/DOWN key.

So it’ll work via BindAction, Could you provide the throttle script

local UserInputService = game:GetService("UserInputService")

UserInputService.InputBegan:Connect(function(inputObject, gameProcessed)
	if script.Parent.Parent.Parent.Parent.CurrentTrain.Value then
		if gameProcessed then return end
		if inputObject.KeyCode == Enum.KeyCode.W then
			while UserInputService:IsKeyDown(Enum.KeyCode.W) do
				if script.Parent.Parent.Parent.Parent.Throttle.Value < 100 then
					script.Parent.Parent.Parent.Parent.Throttle.Value += 0.5
				end
				task.wait()
			end
		elseif inputObject.KeyCode == Enum.KeyCode.S then
			while UserInputService:IsKeyDown(Enum.KeyCode.S) do
				if script.Parent.Parent.Parent.Parent.Throttle.Value > 0 then
					script.Parent.Parent.Parent.Parent.Throttle.Value -= 0.5
				end
				task.wait()
			end
		elseif inputObject.KeyCode == Enum.KeyCode.Up then
			while UserInputService:IsKeyDown(Enum.KeyCode.Up) do
				if script.Parent.Parent.Parent.Parent.Throttle.Value < 100 then
					script.Parent.Parent.Parent.Parent.Throttle.Value += 0.5
				end
				task.wait()
			end
		elseif inputObject.KeyCode == Enum.KeyCode.Down then
			while UserInputService:IsKeyDown(Enum.KeyCode.Down) do
				if script.Parent.Parent.Parent.Parent.Throttle.Value > 0 then
					script.Parent.Parent.Parent.Parent.Throttle.Value -= 0.5
				end
				task.wait()
			end
		end
	end
end)
3 Likes

I will send you my own throttle script in your DMs

1 Like

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