How to smoothly increase a number value

Hi, I am attempting to create a fly script for a player and am using BodyVelocity to move the player in w,a,s,d directions. I have created a user input function so that I can detect which key the player is pressing changing a variable number value and change the direction of the player by using this number to change the Velocity. The only problem is that this is a very janky and un-smooth transition between moving left and moving right, I attempted to use a tween service to smoothly make this transition so it is not as instant, by gradually increasing the variable number value but it did not work. Could someone help me on what to use for this task?

Janky un-smooth movement:
https://gyazo.com/4b09e62f2cf5fe1c91dae70720e496a1

Sample Code:
Direction = {leftForce = 0, rightForce = 0}

    userInput.InputEnded:Connect(function(Input)
             if Input.KeyCode == Enum.KeyCode.D then
        		Direction.rightForce = 1 -is put into a vector3 value later on
             elseif Input.KeyCode == Enum.KeyCode.A then
    		Direction.leftForce = -1
        	end
        end)
1 Like

You may try Tween Service. It helps you to make smooth thinks easyer and more smooth.

1 Like

You could make the tween looped and so it will make it more smooth as theturtlemaster said.
And if they stop flying, you can stop that tween.

Could you give me an example of the code I would have to use. When I used my own it didn’t work.

Can you show us your script?

Simply, put this:

game.TweenService:Create(Direction.rightForce,TweenInfo.new(time),{Value = Value - 1}):Play() Change value into what you are using (Position or something) and change time into an number

The direction is a list of variables. This tween process is not working due to an error: Expected a name, got a complex expression.

Direction = {upForce = 0, forwardForce = 0, backwardForce = 0, leftForce = 0, rightForce = 0}

userInput.InputBegan:Connect(function(Input)
if Input.KeyCode == Enum.KeyCode.W then
Direction.forwardForce = -1
elseif Input.KeyCode == Enum.KeyCode.A then
game.TweenService:Create(Direction.rightForce,TweenInfo.new(time),{Direction.rightForce = Direction.rightForce - 1}):Play()
elseif Input.KeyCode == Enum.KeyCode.D then
end
end)

disable character auto rotate to make this work