So I made my own flying script since I am making a tycoon with a fly tool. But every time I press W or a button it does not change the direction of the player to the camera, and I have to press it again to change the direction which is bad when you are not trying to move in a straight line. I have body gyro but it does nothing to fix it.
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local HumanRootPart = character:WaitForChild("HumanoidRootPart")
local cam = game.Workspace.CurrentCamera
local Debris = game:GetService("Debris")
local UserInputS = game:GetService("UserInputService")
local pressed = false
local Wpressed = false
local Apressed = false
local Spressed = false
local Dpressed = false
local BodyVel
local BodyGyro
local Force = 5000
UserInputS.InputBegan:Connect(function(input, chat)
if not chat then
if input.KeyCode == Enum.KeyCode.Q then
if not pressed then
pressed = true
BodyGyro = Instance.new("BodyGyro")
BodyGyro.MaxTorque = Vector3.new(1, 1, 1)*10^6;
BodyGyro.P = 10^6;
BodyGyro.CFrame = HumanRootPart.CFrame;
BodyVel = Instance.new("BodyVelocity")
BodyVel.Parent = HumanRootPart
BodyVel.P = 2500
BodyVel.MaxForce = Vector3.new(Force,Force,Force)
BodyVel.Velocity = Vector3.new(0,0,0)
--HumanRootPart.CFrame = CFrame.new(cam.CFrame.LookVector)
elseif pressed then
BodyVel:Destroy()
pressed = false
end
end
if input.KeyCode == Enum.KeyCode.W then
BodyVel.Velocity = cam.CFrame.LookVector * 65
BodyGyro.CFrame = cam.CFrame;
Wpressed = true
elseif input.KeyCode == Enum.KeyCode.A then
Apressed = true
BodyVel.Velocity = cam.CFrame.RightVector * -65
elseif input.KeyCode == Enum.KeyCode.S then
Spressed = true
BodyVel.Velocity = cam.CFrame.LookVector * -65
elseif input.KeyCode == Enum.KeyCode.D then
Dpressed = true
BodyVel.Velocity = cam.CFrame.RightVector * 65
end
end
end)
UserInputS.InputEnded:Connect(function(input)
if input.KeyCode == Enum.KeyCode.W then
Wpressed = false
BodyVel.Velocity = Vector3.new(0,0,0)
elseif input.KeyCode == Enum.KeyCode.A then
Apressed = false
BodyVel.Velocity = Vector3.new(0,0,0)
elseif input.KeyCode == Enum.KeyCode.S then
Spressed = false
BodyVel.Velocity = Vector3.new(0,0,0)
elseif input.KeyCode == Enum.KeyCode.D then
Dpressed = false
BodyVel.Velocity = Vector3.new(0,0,0)
end
end)
I also tried a loop on the body velocity but it kept going even if I did not press the button
Any help would be welcomed.