So I am working on a spacecraft, and I am using A and D keys for rotating, but only the D key works, despite being set up in the same way, and the script does get to both lines, I am 100% sure of that.
The variables are coming from a RemoteEvent, they are; Ship: The spacecraft model, Key: String of Key, KeyState: Whether the key is up or down
Ship,Key,KeyState
if Key == "A" then
if KeyState == true then
--This line is reached, but the spacecraft does not turn
Ship.C.Center.HorizontalTurn.AngularVelocity = Vector3.new(0,0,3.5)
else
Ship.C.Center.HorizontalTurn.AngularVelocity = Vector3.new(0,0,0)
end
end
if Key == "D" then
if KeyState == true then
--This line is reached, and the spacecraft turns
Ship.C.Center.HorizontalTurn.AngularVelocity = Vector3.new(0,0,-3.5)
else
Ship.C.Center.HorizontalTurn.AngularVelocity = Vector3.new(0,0,0)
end
end
Have you tried swapping the actions to see if the problem is the A key or if the problem is in turning? Have you tried increasing the angular velocity to a higher value to see if that causes any difference when pushing A?
Your second if statement is seeing that Key is not “D” and is changing the velocity to 0,0,0. So change it to
if Key == "A" then
if KeyState == true then
--This line is reached, but the spacecraft does not turn
Ship.C.Center.HorizontalTurn.AngularVelocity = Vector3.new(0,0,3.5)
end
elseif Key == "D" then
if KeyState == true then
--This line is reached, and the spacecraft turns
Ship.C.Center.HorizontalTurn.AngularVelocity = Vector3.new(0,0,-3.5)
end
else
Ship.C.Center.HorizontalTurn.AngularVelocity = Vector3.new(0,0,0)
end
Yes, I realized the problem was that since A and D controls rotation, and W controls motion forward (not shown in script), and they were firing at the same time, W key was basically making the other 2 be ignored, though not always, hence why D worked and A didn’t. Turns out sometimes D did not work either. I just made another RemoteEvent for controlling movement forward, and it works now.