Changing DesiredAngle (Motor) via keybindings

So basiclly I am trying to animate an plane (F35), but basicly how do I make it so when me or an player presses “G” on their keyboard the desired angle of the motor changes to -1.8

Pics:
https://gyazo.com/d40a26ad646b9878b0f569828938bfaa

What I have tried:

game:GetService("UserInputService").Enum.KeyCode.G

if geardown == true then
  geardown == false

if geardown == true then

script.Parent.Parent.Animation.LG.Motor.DesiredAngle = -1.8
script.Parent.Parent.Animation.FG.Motor.DesiredAngle = -1.8
script.Parent.Parent.Animation.RG.Motor.DesiredAngle = -1.8

if geardown == false then 
script.Parent.Parent.Animation.LG.Motor.DesiredAngle = 0
script.Parent.Parent.Animation.FG.Motor.DesiredAngle = 0
script.Parent.Parent.Animation.RG.Motor.DesiredAngle = 0

end
end

Hello, here’s a few reasons why this wouldn’t work:

This part here, as soon as the geardown hits true, you set it to false straight away meaning that the if statement below that:

Will never actually run, beacause geardown is false. This means that your Motor will never be changed. What you should do is make sure your correcting your values, also your UserInputService should be used like this:


local UserInputService = game:GetService("UserInputService")
local KeyCode = Enum.KeyCode.G

UserInputService.InputBegan:Connect(function(key)
      if key == KeyCode then 
       --[[ assuming they want to lower the landing gear, 
             so you want to set your geardown value to true here. Then 
             Your going to want to change your Motor angle. Once thats done,
             if you want the user to have it where if they press G again, 
             and the gear goes up, use a debounce. 
        ]]--
end)

How do I input the debounce in to the script?

Your debounce would go like this:

local UserInputService = game:GetService("UserInputService")
local KeyCode = Enum.KeyCode.G
local debounce = false 

UserInputService.InputBegan:Connect(function(key)
      if key == KeyCode then 
         if debounce == false then 
           -- lower your gear
           debounce = true -- set debounce to true
         else 
          if debounce == true then 
           -- raise gear
           debounce = false -- set debounce to false 
          end 
end)

You should start reading up on some topics, they are very easy to find and help you learn new things when it comes to programming that will benefit you in the future.

Topics used in this would be Debounce, if/else statements, UserInputService, Enum and Keycodes (pretty much in your UserInputService) and then just basic functions.

1 Like

https://gyazo.com/51d6c03f5a98ba13a49bf3fa12a3c7a0

How to fix bc I am trying but cant find how to

You need to add an end after your “then” , you just need to add end on line 1615