I’m trying to fix an issue with my spaceship.
Currently, when you press q, the nose does go up as it should, but when holding it, it bounces. Same with e, but with going down. Also, I sometimes get an ‘unable to cast CoordinateFrame (Cframe) to float’ error when I press q and d at the same time (so going up and turning at the same time).
https://gyazo.com/fcbb94ae92d33e15994ce8082f82d974
Here’s my code for when the player presses a key.
KeyFunction.OnServerInvoke = (function(Player, Key, Action)
if BG and BP then
if Action == "KeyDown" then
if Key == "q" then
QPressed = true
EPressed = false
spawn(function()
while QPressed == true do
wait()
XRotation = XRotation + .01
BG.CFrame = BG.CFrame * CFrame.fromEulerAnglesXYZ(XRotation, YRotation, ZRotation)
end
end)
elseif Key == "e" then
EPressed = true
QPressed = false
spawn(function()
while EPressed == true do
wait()
XRotation = XRotation - .01
BG.CFrame = BG.CFrame * CFrame.fromEulerAnglesXYZ(XRotation, YRotation, ZRotation)
end
end)
elseif Key == "z" then
ZPressed = true
XPressed = false
spawn(function()
while ZPressed == true do
wait()
ZRotation = ZRotation + .01
BG.CFrame = BG.CFrame * CFrame.fromEulerAnglesXYZ(XRotation, YRotation, ZRotation)
end
end)
elseif Key == "x" then
XPressed = true
ZPressed = false
spawn(function()
while XPressed == true do
wait()
ZRotation = ZRotation - .01
BG.CFrame = BG.CFrame * CFrame.fromEulerAnglesXYZ(XRotation, YRotation, ZRotation)
end
end)
end
elseif Action == "KeyUp" then
if Key == "q" then
QPressed = false
elseif Key == "e" then
EPressed = false
elseif Key == "z" then
ZPressed = false
elseif Key == "x" then
XPressed = false
end
end
end
end)
I’ve tried not doing
BG.CFrame = BG.CFrame * (whatever angle it is)
And instead doing
BG.CFrame = (Angles)
but that made it so it turned the ship in a different direction entirely when you pressed a diff key.