You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-- Flying Script for Roblox (Character Controlled)
-- Variables
local player = game.Players.LocalPlayer
local flying = false
local speed = 50 -- Flight speed
local liftSpeed = 20 -- Vertical speed (up/down)
-- Create a BodyGyro and BodyVelocity to control movement
local function startFlying(character)
if not character:FindFirstChild("Humanoid") then return end
local humanoid = character.Humanoid
-- Create a BodyGyro and BodyVelocity to control flight
local bodyGyro = Instance.new("BodyGyro")
bodyGyro.Parent = character.HumanoidRootPart
bodyGyro.MaxTorque = Vector3.new(4000, 4000, 4000)
bodyGyro.D = 20 -- Turn speed
local bodyVelocity = Instance.new("BodyVelocity")
bodyVelocity.Parent = character.HumanoidRootPart
bodyVelocity.MaxForce = Vector3.new(4000, 4000, 4000)
bodyVelocity.Velocity = Vector3.new(0, 0, 0)
-- Handle controls for flying
local userInputService = game:GetService("UserInputService")
-- Control variables
local direction = Vector3.new(0, 0, 0) -- Movement direction
local isFlying = true -- Flying status
-- Update loop for flight
local function fly()
while isFlying and character:FindFirstChild("HumanoidRootPart") do
-- Update velocity and gyro for flight
bodyVelocity.Velocity = direction * speed
bodyGyro.CFrame = character.HumanoidRootPart.CFrame * CFrame.Angles(0, math.rad(player.Character.HumanoidRootPart.Orientation.Y), 0)
wait(0.01)
end
-- Clean up when flight ends
bodyGyro:Destroy()
bodyVelocity:Destroy()
end
-- Start flying
fly()
end
-- Function to handle player input (WASD for movement)
local function onKeyPress(input, gameProcessed)
if not flying or gameProcessed then return end
-- Check for WASD input to move in different directions
if input.KeyCode == Enum.KeyCode.W then
direction = direction + player.Character.HumanoidRootPart.CFrame.LookVector
elseif input.KeyCode == Enum.KeyCode.S then
direction = direction - player.Character.HumanoidRootPart.CFrame.LookVector
elseif input.KeyCode == Enum.KeyCode.A then
direction = direction - player.Character.HumanoidRootPart.CFrame.RightVector
elseif input.KeyCode == Enum.KeyCode.D then
direction = direction + player.Character.HumanoidRootPart.CFrame.RightVector
elseif input.KeyCode == Enum.KeyCode.Space then
-- Move up
direction = direction + Vector3.new(0, 1, 0) * liftSpeed
elseif input.KeyCode == Enum.KeyCode.LeftControl then
-- Move down
direction = directi
The text was updated successfully, but these errors were encountered:
-- Flying Script for Roblox (Character Controlled)
-- Variables
local player = game.Players.LocalPlayer
local flying = false
local speed = 50 -- Flight speed
local liftSpeed = 20 -- Vertical speed (up/down)
-- Create a BodyGyro and BodyVelocity to control movement
local function startFlying(character)
if not character:FindFirstChild("Humanoid") then return end
end
-- Function to handle player input (WASD for movement)
local function onKeyPress(input, gameProcessed)
if not flying or gameProcessed then return end
The text was updated successfully, but these errors were encountered: