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
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)
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.