I’ve made a flight system, but I can only move on one axis. I’m pretty sure the issue is HRP.CFrame.LookVector
, but I’m not sure what to do.
local player = game.Players.LocalPlayer
local char = player.Character
local HRP = char:WaitForChild("HumanoidRootPart")
local RS = game:GetService("RunService")
local CAS = game:GetService("ContextActionService")
local UIS = game:GetService("UserInputService")
local LV = script.LinearVelocity
local speed = 50
local flying = true
local clone = LV:Clone()
clone.Name = "LV"
function Fly(action, state)
if state == Enum.UserInputState.Begin then
local conn = nil
if flying then
local att = Instance.new("Attachment")
att.Name = "Att"
att.Parent = HRP
clone.Attachment0 = att
clone.Parent = HRP
conn = RS.RenderStepped:Connect(function()
local vel = Vector3.new(0,0,0)
if UIS:IsKeyDown(Enum.KeyCode.W) then
vel += Vector3.new(0,0,speed) * HRP.CFrame.LookVector
elseif UIS:IsKeyDown(Enum.KeyCode.S) then
vel += Vector3.new(0,0,-speed) * HRP.CFrame.LookVector
end
clone.VectorVelocity = vel
end)
flying = false
else
if HRP:FindFirstChild("LV") and HRP:FindFirstChild("Att") then
HRP.LV.VectorVelocity = Vector3.new(0,0,0)
HRP.Att:Destroy()
if conn ~= nil then conn:Disconnect() end
end
flying = true
end
end
end
CAS:BindAction("Fly", Fly, true, Enum.KeyCode.E)