--!strict local Players = game:GetService("Players") local UserInputService = game:GetService("UserInputService") local RunService = game:GetService("RunService") local player = Players.LocalPlayer local flying = false local speed = 100 local attachment: Attachment? = nil local velocity: LinearVelocity? = nil local connection: RBXScriptConnection? = nil local function stopFlying() flying = false if connection then connection:Disconnect() connection = nil end if velocity then velocity:Destroy() velocity = nil end if attachment then attachment:Destroy() attachment = nil end end local function startFlying() local character = player.Character local humanoid = character and character:FindFirstChildOfClass("Humanoid") local root = character and character:FindFirstChild("HumanoidRootPart") if not humanoid or not root or not root:IsA("BasePart") then return end flying = true attachment = Instance.new("Attachment") attachment.Parent = root velocity = Instance.new("LinearVelocity") velocity.Attachment0 = attachment velocity.RelativeTo = Enum.ActuatorRelativeTo.World velocity.MaxForce = 100000 velocity.VectorVelocity = Vector3.zero velocity.Parent = root connection = RunService.RenderStepped:Connect(function() if not flying or not velocity then return end local camera = workspace.CurrentCamera if not camera then return end local direction = Vector3.zero if UserInputService:IsKeyDown(Enum.KeyCode.W) then direction += camera.CFrame.LookVector end if UserInputService:IsKeyDown(Enum.KeyCode.S) then direction -= camera.CFrame.LookVector end if UserInputService:IsKeyDown(Enum.KeyCode.D) then direction += camera.CFrame.RightVector end if UserInputService:IsKeyDown(Enum.KeyCode.A) then direction -= camera.CFrame.RightVector end if UserInputService:IsKeyDown(Enum.KeyCode.Space) then direction += Vector3.yAxis end if UserInputService:IsKeyDown(Enum.KeyCode.LeftControl) then direction -= Vector3.yAxis end velocity.VectorVelocity = direction.Magnitude > 0 and direction.Unit * speed or Vector3.zero end) end UserInputService.InputBegan:Connect(function(input, processed) if processed then return end if input.KeyCode == Enum.KeyCode.K then if flying then stopFlying() else startFlying() end end end) player.CharacterAdded:Connect(function() stopFlying() end)