-- LocalScript in StarterPlayerScripts local UIS = game:GetService("UserInputService") local RunService = game:GetService("RunService") local player = game.Players.LocalPlayer local flying = false local speed = 60 local vectorForce local bodyGyro local attachment local function startFlying(character) local root = character:WaitForChild("HumanoidRootPart") -- Attachment for force attachment = Instance.new("Attachment") attachment.Parent = root -- Cancel gravity vectorForce = Instance.new("VectorForce") vectorForce.Attachment0 = attachment vectorForce.RelativeTo = Enum.ActuatorRelativeTo.World local mass = root.AssemblyMass local gravity = workspace.Gravity vectorForce.Force = Vector3.new(0, mass * gravity, 0) vectorForce.Parent = root -- Rotation control bodyGyro = Instance.new("BodyGyro") bodyGyro.MaxTorque = Vector3.new(1,1,1) * 1e5 bodyGyro.CFrame = root.CFrame bodyGyro.Parent = root end local function stopFlying() if vectorForce then vectorForce:Destroy() end if bodyGyro then bodyGyro:Destroy() end if attachment then attachment:Destroy() end end UIS.InputBegan:Connect(function(input, gp) if gp then return end if input.KeyCode == Enum.KeyCode.F then flying = not flying local character = player.Character or player.CharacterAdded:Wait() if flying then startFlying(character) else stopFlying() end end end) RunService.RenderStepped:Connect(function() if not flying then return end local character = player.Character if not character then return end local root = character:FindFirstChild("HumanoidRootPart") if not root then return end local camera = workspace.CurrentCamera local direction = Vector3.zero if UIS:IsKeyDown(Enum.KeyCode.W) then direction += camera.CFrame.LookVector end if UIS:IsKeyDown(Enum.KeyCode.S) then direction -= camera.CFrame.LookVector end if UIS:IsKeyDown(Enum.KeyCode.A) then direction -= camera.CFrame.RightVector end if UIS:IsKeyDown(Enum.KeyCode.D) then direction += camera.CFrame.RightVector end if direction.Magnitude > 0 then root.AssemblyLinearVelocity = direction.Unit * speed else root.AssemblyLinearVelocity = Vector3.zero end bodyGyro.CFrame = camera.CFrame end)