Advertisement
YESSIR455bb

Fly script

May 11th, 2025 (edited)
15
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.41 KB | None | 0 0
  1. --[[
  2.  
  3.  
  4. FEATURES:
  5. - Double-tap space to toggle flight
  6. - WASD to move, Space to go up, Shift to go down
  7. - Q/E to adjust speed
  8. - Visual effects and trail
  9.  
  10.  
  11. ]]--
  12.  
  13. -- Services
  14. local UserInputService = game:GetService("UserInputService")
  15. local RunService = game:GetService("RunService")
  16. local Players = game:GetService("Players")
  17. local TweenService = game:GetService("TweenService")
  18.  
  19. -- Variables
  20. local Player = Players.LocalPlayer
  21. local Character = Player.Character or Player.CharacterAdded:Wait()
  22. local Camera = workspace.CurrentCamera
  23. local flying = false
  24. local flySpeed = 50
  25. local minSpeed = 10
  26. local maxSpeed = 150
  27. local lastSpace = 0
  28. local doubleTapTime = 0.3
  29. local bodyVelocity
  30. local bodyGyro
  31. local flightGui
  32. local controlsGui
  33. local trailEffect
  34. local particleEffect
  35. local particleAttachment
  36.  
  37. -- Create permanent controls UI
  38. local function createControlsUI()
  39. if controlsGui then controlsGui:Destroy() end
  40.  
  41. controlsGui = Instance.new("ScreenGui")
  42. controlsGui.Name = "FlightControlsGui"
  43. controlsGui.ResetOnSpawn = false
  44. controlsGui.Parent = Player.PlayerGui
  45.  
  46. local frame = Instance.new("Frame")
  47. frame.Size = UDim2.new(0, 230, 0, 120)
  48. frame.Position = UDim2.new(0, 20, 1, -140)
  49. frame.BackgroundColor3 = Color3.fromRGB(0, 0, 0)
  50. frame.BackgroundTransparency = 0.6
  51. frame.BorderSizePixel = 0
  52. frame.Parent = controlsGui
  53.  
  54. local corner = Instance.new("UICorner")
  55. corner.CornerRadius = UDim.new(0, 10)
  56. corner.Parent = frame
  57.  
  58. local title = Instance.new("TextLabel")
  59. title.Size = UDim2.new(1, 0, 0, 30)
  60. title.Position = UDim2.new(0, 0, 0, 5)
  61. title.BackgroundTransparency = 1
  62. title.TextColor3 = Color3.fromRGB(255, 255, 255)
  63. title.Text = "Flight Controls"
  64. title.Font = Enum.Font.GothamBold
  65. title.TextSize = 16
  66. title.Parent = frame
  67.  
  68. local controls = {
  69. "Double-Space: Toggle Flight",
  70. "WASD: Move Direction",
  71. "Space: Fly Up",
  72. "Shift: Fly Down",
  73. "Q/E: Adjust Speed"
  74. }
  75.  
  76. for i, control in ipairs(controls) do
  77. local label = Instance.new("TextLabel")
  78. label.Size = UDim2.new(1, -20, 0, 16)
  79. label.Position = UDim2.new(0, 10, 0, 30 + (i * 17))
  80. label.BackgroundTransparency = 1
  81. label.TextColor3 = Color3.fromRGB(200, 200, 200)
  82. label.Text = control
  83. label.TextXAlignment = Enum.TextXAlignment.Left
  84. label.Font = Enum.Font.Gotham
  85. label.TextSize = 14
  86. label.Parent = frame
  87. end
  88.  
  89. -- Animate in
  90. frame.Position = UDim2.new(-0.3, 0, 1, -140)
  91. local tween = TweenService:Create(
  92. frame,
  93. TweenInfo.new(0.8, Enum.EasingStyle.Back, Enum.EasingDirection.Out),
  94. {Position = UDim2.new(0, 20, 1, -140)}
  95. )
  96. tween:Play()
  97. end
  98.  
  99. -- Create the flight UI
  100. local function createFlightUI()
  101. -- Remove any existing UI
  102. if flightGui then flightGui:Destroy() end
  103.  
  104. -- Create new UI
  105. flightGui = Instance.new("ScreenGui")
  106. flightGui.Name = "FlightGui"
  107. flightGui.ResetOnSpawn = false
  108. flightGui.Parent = Player.PlayerGui
  109.  
  110. local frame = Instance.new("Frame")
  111. frame.Size = UDim2.new(0, 200, 0, 80)
  112. frame.Position = UDim2.new(1, -220, 0, 20)
  113. frame.BackgroundColor3 = Color3.fromRGB(0, 0, 0)
  114. frame.BackgroundTransparency = 0.5
  115. frame.BorderSizePixel = 0
  116. frame.Parent = flightGui
  117.  
  118. local corner = Instance.new("UICorner")
  119. corner.CornerRadius = UDim.new(0, 10)
  120. corner.Parent = frame
  121.  
  122. local statusLabel = Instance.new("TextLabel")
  123. statusLabel.Name = "StatusLabel"
  124. statusLabel.Size = UDim2.new(1, 0, 0, 30)
  125. statusLabel.Position = UDim2.new(0, 0, 0, 10)
  126. statusLabel.BackgroundTransparency = 1
  127. statusLabel.TextColor3 = Color3.fromRGB(0, 255, 128)
  128. statusLabel.Text = "FLIGHT: ACTIVE"
  129. statusLabel.Font = Enum.Font.GothamBold
  130. statusLabel.TextSize = 18
  131. statusLabel.Parent = frame
  132.  
  133. local speedLabel = Instance.new("TextLabel")
  134. speedLabel.Name = "SpeedLabel"
  135. speedLabel.Size = UDim2.new(1, 0, 0, 20)
  136. speedLabel.Position = UDim2.new(0, 0, 0, 40)
  137. speedLabel.BackgroundTransparency = 1
  138. speedLabel.TextColor3 = Color3.fromRGB(255, 255, 255)
  139. speedLabel.Text = "Speed: " .. flySpeed
  140. speedLabel.Font = Enum.Font.Gotham
  141. speedLabel.TextSize = 14
  142. speedLabel.Parent = frame
  143.  
  144. -- Animate UI in
  145. frame.Position = UDim2.new(1, 50, 0, 20)
  146. local tween = TweenService:Create(
  147. frame,
  148. TweenInfo.new(0.5, Enum.EasingStyle.Back, Enum.EasingDirection.Out),
  149. {Position = UDim2.new(1, -220, 0, 20)}
  150. )
  151. tween:Play()
  152.  
  153. -- Return the speed label for updates
  154. return speedLabel
  155. end
  156.  
  157. -- Update the speed display
  158. local function updateSpeedDisplay()
  159. if flightGui and flightGui.Parent then
  160. local speedLabel = flightGui:FindFirstChild("Frame"):FindFirstChild("SpeedLabel")
  161. if speedLabel then
  162. speedLabel.Text = "Speed: " .. flySpeed
  163. end
  164. end
  165. end
  166.  
  167. -- Create visual effects
  168. local function createVisualEffects()
  169. local rootPart = Character:FindFirstChild("HumanoidRootPart")
  170. if not rootPart then return end
  171.  
  172. -- Create trail effect
  173. trailEffect = Instance.new("Trail")
  174. trailEffect.Attachment0 = Instance.new("Attachment", rootPart)
  175. trailEffect.Attachment0.Position = Vector3.new(0, -1, 0)
  176. trailEffect.Attachment1 = Instance.new("Attachment", rootPart)
  177. trailEffect.Attachment1.Position = Vector3.new(0, 1, 0)
  178. trailEffect.Color = ColorSequence.new({
  179. ColorSequenceKeypoint.new(0, Color3.fromRGB(255, 255, 255)),
  180. ColorSequenceKeypoint.new(0.5, Color3.fromRGB(100, 200, 255)),
  181. ColorSequenceKeypoint.new(1, Color3.fromRGB(0, 100, 255))
  182. })
  183. trailEffect.Transparency = NumberSequence.new({
  184. NumberSequenceKeypoint.new(0, 0.8),
  185. NumberSequenceKeypoint.new(0.5, 0.5),
  186. NumberSequenceKeypoint.new(1, 0.8)
  187. })
  188. trailEffect.Lifetime = 0.5
  189. trailEffect.WidthScale = NumberSequence.new({
  190. NumberSequenceKeypoint.new(0, 0.5),
  191. NumberSequenceKeypoint.new(0.5, 1),
  192. NumberSequenceKeypoint.new(1, 0.5)
  193. })
  194. trailEffect.Parent = rootPart
  195.  
  196. -- Create particle effect
  197. particleAttachment = Instance.new("Attachment")
  198. particleAttachment.Position = Vector3.new(0, 0, 0)
  199. particleAttachment.Parent = rootPart
  200.  
  201. particleEffect = Instance.new("ParticleEmitter")
  202. particleEffect.Color = ColorSequence.new({
  203. ColorSequenceKeypoint.new(0, Color3.fromRGB(255, 255, 255)),
  204. ColorSequenceKeypoint.new(1, Color3.fromRGB(100, 200, 255))
  205. })
  206. particleEffect.Transparency = NumberSequence.new({
  207. NumberSequenceKeypoint.new(0, 0.8),
  208. NumberSequenceKeypoint.new(0.5, 0.5),
  209. NumberSequenceKeypoint.new(1, 1)
  210. })
  211. particleEffect.LightEmission = 0.5
  212. particleEffect.LightInfluence = 0
  213. particleEffect.Size = NumberSequence.new({
  214. NumberSequenceKeypoint.new(0, 0.2),
  215. NumberSequenceKeypoint.new(1, 0)
  216. })
  217. particleEffect.Texture = "rbxassetid://241267873" -- Sparkle particle
  218. particleEffect.Acceleration = Vector3.new(0, 0, 0)
  219. particleEffect.Lifetime = NumberRange.new(0.5, 1)
  220. particleEffect.Rate = 50
  221. particleEffect.Speed = NumberRange.new(3, 5)
  222. particleEffect.SpreadAngle = Vector2.new(180, 180)
  223. particleEffect.Parent = particleAttachment
  224. end
  225.  
  226. -- Remove visual effects
  227. local function removeVisualEffects()
  228. if trailEffect then
  229. if trailEffect.Attachment0 then trailEffect.Attachment0:Destroy() end
  230. if trailEffect.Attachment1 then trailEffect.Attachment1:Destroy() end
  231. trailEffect:Destroy()
  232. trailEffect = nil
  233. end
  234.  
  235. if particleEffect then
  236. particleEffect:Destroy()
  237. particleEffect = nil
  238. end
  239.  
  240. if particleAttachment then
  241. particleAttachment:Destroy()
  242. particleAttachment = nil
  243. end
  244. end
  245.  
  246. -- Start flying
  247. local function startFlying()
  248. if flying then return end
  249.  
  250. -- Wait for character and humanoid
  251. if not Character or not Character.Parent then
  252. Character = Player.Character
  253. if not Character then return end
  254. end
  255.  
  256. local humanoid = Character:FindFirstChildOfClass("Humanoid")
  257. local rootPart = Character:FindFirstChild("HumanoidRootPart")
  258. if not humanoid or not rootPart then return end
  259.  
  260. -- Set flying flag
  261. flying = true
  262.  
  263. -- Remove existing flight physics objects
  264. if bodyVelocity then bodyVelocity:Destroy() end
  265. if bodyGyro then bodyGyro:Destroy() end
  266.  
  267. -- Create new flight physics objects
  268. bodyVelocity = Instance.new("BodyVelocity")
  269. bodyVelocity.Name = "FlightVelocity"
  270. bodyVelocity.MaxForce = Vector3.new(10000, 10000, 10000)
  271. bodyVelocity.Velocity = Vector3.new(0, 0, 0)
  272. bodyVelocity.Parent = rootPart
  273.  
  274. bodyGyro = Instance.new("BodyGyro")
  275. bodyGyro.Name = "FlightGyro"
  276. bodyGyro.MaxTorque = Vector3.new(10000, 10000, 10000)
  277. bodyGyro.P = 1000
  278. bodyGyro.D = 100
  279. bodyGyro.CFrame = rootPart.CFrame
  280. bodyGyro.Parent = rootPart
  281.  
  282. -- Create the flight UI
  283. local speedLabel = createFlightUI()
  284.  
  285. -- Create visual effects
  286. createVisualEffects()
  287.  
  288. -- Flight loop
  289. local connection = RunService.RenderStepped:Connect(function()
  290. if not flying or not Character.Parent then
  291. connection:Disconnect()
  292. return
  293. end
  294.  
  295. -- Control the character's state to prevent falling animation
  296. if humanoid and humanoid.Parent then
  297. humanoid:ChangeState(Enum.HumanoidStateType.Physics)
  298. end
  299.  
  300. -- Calculate flight direction
  301. local moveDirection = Vector3.new(0, 0, 0)
  302.  
  303. -- Forward/Backward
  304. if UserInputService:IsKeyDown(Enum.KeyCode.W) then
  305. moveDirection = moveDirection + Camera.CFrame.LookVector
  306. end
  307. if UserInputService:IsKeyDown(Enum.KeyCode.S) then
  308. moveDirection = moveDirection - Camera.CFrame.LookVector
  309. end
  310.  
  311. -- Left/Right
  312. if UserInputService:IsKeyDown(Enum.KeyCode.A) then
  313. moveDirection = moveDirection - Camera.CFrame.RightVector
  314. end
  315. if UserInputService:IsKeyDown(Enum.KeyCode.D) then
  316. moveDirection = moveDirection + Camera.CFrame.RightVector
  317. end
  318.  
  319. -- Up/Down
  320. if UserInputService:IsKeyDown(Enum.KeyCode.Space) then
  321. moveDirection = moveDirection + Vector3.new(0, 1, 0)
  322. end
  323. if UserInputService:IsKeyDown(Enum.KeyCode.LeftShift) then
  324. moveDirection = moveDirection - Vector3.new(0, 1, 0)
  325. end
  326.  
  327. -- Apply velocity
  328. if moveDirection.Magnitude > 0 then
  329. bodyVelocity.Velocity = moveDirection.Unit * flySpeed
  330. else
  331. bodyVelocity.Velocity = Vector3.new(0, 0, 0)
  332. end
  333.  
  334. -- Update bodyGyro to face camera direction
  335. bodyGyro.CFrame = Camera.CFrame
  336. end)
  337.  
  338. -- Clean up when character is removed
  339. Character.AncestryChanged:Connect(function(_, parent)
  340. if not parent and flying then
  341. stopFlying()
  342. end
  343. end)
  344. end
  345.  
  346. -- Stop flying and PROPERLY RESTORE WALKING
  347. local function stopFlying()
  348. if not flying then return end
  349. flying = false
  350.  
  351. -- Clean up physics objects
  352. if bodyVelocity then bodyVelocity:Destroy(); bodyVelocity = nil end
  353. if bodyGyro then bodyGyro:Destroy(); bodyGyro = nil end
  354.  
  355. -- Remove visual effects
  356. removeVisualEffects()
  357.  
  358. -- Find the humanoid
  359. local humanoid = Character and Character:FindFirstChildOfClass("Humanoid")
  360. if humanoid then
  361. -- Important: This sequence of state changes fixes the stuck animation
  362. task.spawn(function()
  363. -- First reset to GettingUp (transition state)
  364. humanoid:ChangeState(Enum.HumanoidStateType.GettingUp)
  365.  
  366. -- Brief delay to let the physics settle
  367. task.wait(0.1)
  368.  
  369. -- Then force to Running state (allows walking again)
  370. humanoid:ChangeState(Enum.HumanoidStateType.Running)
  371.  
  372. -- If still not working, try landing mode
  373. task.wait(0.1)
  374. if humanoid:GetState() ~= Enum.HumanoidStateType.Running then
  375. humanoid:ChangeState(Enum.HumanoidStateType.Landed)
  376. task.wait(0.1)
  377. humanoid:ChangeState(Enum.HumanoidStateType.Running)
  378. end
  379. end)
  380. end
  381.  
  382. -- Update flight UI without removing it
  383. if flightGui and flightGui.Parent then
  384. local frame = flightGui:FindFirstChild("Frame")
  385. if frame then
  386. -- Update status label
  387. local statusLabel = frame:FindFirstChild("StatusLabel")
  388. if statusLabel then
  389. statusLabel.Text = "FLIGHT: DISABLED"
  390. statusLabel.TextColor3 = Color3.fromRGB(255, 100, 100)
  391. end
  392. end
  393. end
  394. end
  395.  
  396. -- Adjust flight speed
  397. local function adjustSpeed(change)
  398. flySpeed = math.clamp(flySpeed + change, minSpeed, maxSpeed)
  399. updateSpeedDisplay()
  400. end
  401.  
  402. -- Handle input for flight control
  403. UserInputService.InputBegan:Connect(function(input, gameProcessed)
  404. if gameProcessed then return end
  405.  
  406. -- Double space to toggle flight
  407. if input.KeyCode == Enum.KeyCode.Space then
  408. local now = tick()
  409. if now - lastSpace < doubleTapTime then
  410. if flying then
  411. stopFlying()
  412. else
  413. startFlying()
  414. end
  415. end
  416. lastSpace = now
  417. end
  418.  
  419. -- Speed control when flying
  420. if flying then
  421. if input.KeyCode == Enum.KeyCode.Q then
  422. adjustSpeed(-10)
  423. elseif input.KeyCode == Enum.KeyCode.E then
  424. adjustSpeed(10)
  425. end
  426. end
  427. end)
  428.  
  429. -- Show notification on script load
  430. local function showNotification()
  431. local notification = Instance.new("ScreenGui")
  432. notification.Name = "FlightNotification"
  433. notification.Parent = Player.PlayerGui
  434.  
  435. local frame = Instance.new("Frame")
  436. frame.Size = UDim2.new(0, 300, 0, 100)
  437. frame.Position = UDim2.new(0.5, -150, 0, -100)
  438. frame.BackgroundColor3 = Color3.fromRGB(0, 0, 0)
  439. frame.BackgroundTransparency = 0.5
  440. frame.BorderSizePixel = 0
  441. frame.Parent = notification
  442.  
  443. local corner = Instance.new("UICorner")
  444. corner.CornerRadius = UDim.new(0, 10)
  445. corner.Parent = frame
  446.  
  447. local title = Instance.new("TextLabel")
  448. title.Size = UDim2.new(1, 0, 0, 30)
  449. title.Position = UDim2.new(0, 0, 0, 10)
  450. title.BackgroundTransparency = 1
  451. title.TextColor3 = Color3.fromRGB(255, 255, 255)
  452. title.Font = Enum.Font.GothamBold
  453. title.TextSize = 18
  454. title.Text = "Flight Mode Available"
  455. title.Parent = frame
  456.  
  457. local desc = Instance.new("TextLabel")
  458. desc.Size = UDim2.new(1, 0, 0, 60)
  459. desc.Position = UDim2.new(0, 0, 0, 40)
  460. desc.BackgroundTransparency = 1
  461. desc.TextColor3 = Color3.fromRGB(200, 200, 200)
  462. desc.Font = Enum.Font.Gotham
  463. desc.TextSize = 14
  464. desc.Text = "Double-tap SPACE to toggle flight\nControls are shown in the bottom-left corner"
  465. desc.Parent = frame
  466.  
  467. -- Animate in
  468. local tweenIn = TweenService:Create(
  469. frame,
  470. TweenInfo.new(0.8, Enum.EasingStyle.Back, Enum.EasingDirection.Out),
  471. {Position = UDim2.new(0.5, -150, 0, 20)}
  472. )
  473. tweenIn:Play()
  474.  
  475. -- Animate out after delay
  476. task.delay(5, function()
  477. local tweenOut = TweenService:Create(
  478. frame,
  479. TweenInfo.new(0.5, Enum.EasingStyle.Quad, Enum.EasingDirection.In),
  480. {Position = UDim2.new(0.5, -150, 0, -100)}
  481. )
  482. tweenOut:Play()
  483.  
  484. task.delay(0.5, function()
  485. notification:Destroy()
  486. end)
  487. end)
  488. end
  489.  
  490. -- Handle character respawning
  491. Player.CharacterAdded:Connect(function(newCharacter)
  492. Character = newCharacter
  493.  
  494. if flying then
  495. stopFlying()
  496. task.wait(1)
  497. startFlying()
  498. end
  499. end)
  500.  
  501. -- Show initial notification
  502. showNotification()
  503.  
  504. -- Create permanent controls display
  505. createControlsUI()
  506.  
  507. print("Complete Flight Script loaded! Double-tap SPACE to toggle flight mode.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement