Advertisement
Sheepz

TP Fly Script (ROBLOX SCRIPT)

Jul 30th, 2023 (edited)
2,668
2
Never
5
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.73 KB | Source Code | 2 0
  1. -- this script was made by me (Sheepz).
  2.  
  3. local player = game.Players.LocalPlayer
  4. local character = player.Character
  5. local humanoid = character and character:FindFirstChild("Humanoid")
  6.  
  7. local flying = false
  8. local flySpeed = 50 -- you can adjust this value to change the flying speed.
  9.  
  10.  
  11. local function enableFlying()
  12.     if humanoid then
  13.         humanoid.PlatformStand = true
  14.         humanoid.AutoRotate = false
  15.         humanoid:SetStateEnabled(Enum.HumanoidStateType.Flying, true)
  16.         flying = true
  17.     end
  18. end
  19.  
  20.  
  21. local function disableFlying()
  22.     if humanoid then
  23.         humanoid.PlatformStand = false
  24.         humanoid.AutoRotate = true
  25.         humanoid:SetStateEnabled(Enum.HumanoidStateType.Flying, false)
  26.         flying = false
  27.     end
  28. end
  29.  
  30.  
  31. local function handleInput(input, gameProcessedEvent)
  32.     if gameProcessedEvent then
  33.         return
  34.     end
  35.  
  36.     if flying and input.UserInputType == Enum.UserInputType.Keyboard then
  37.         local moveVector = Vector3.new()
  38.  
  39.         if input.KeyCode == Enum.KeyCode.W then
  40.             moveVector = moveVector + Vector3.new(0, 0, -1)
  41.         end
  42.         if input.KeyCode == Enum.KeyCode.S then
  43.             moveVector = moveVector + Vector3.new(0, 0, 1)
  44.         end
  45.         if input.KeyCode == Enum.KeyCode.A then
  46.             moveVector = moveVector + Vector3.new(-1, 0, 0)
  47.         end
  48.         if input.KeyCode == Enum.KeyCode.D then
  49.             moveVector = moveVector + Vector3.new(1, 0, 0)
  50.         end
  51.  
  52.         character:SetPrimaryPartCFrame(CFrame.new(character.PrimaryPart.Position + moveVector * flySpeed))
  53.     end
  54. end
  55.  
  56.  
  57. game:GetService("UserInputService").InputBegan:Connect(handleInput)
  58. game:GetService("UserInputService").InputChanged:Connect(handleInput)
  59.  
  60.  
  61. local gui = Instance.new("ScreenGui")
  62. gui.Parent = player.PlayerGui
  63. gui.Name = "TPFlyingGUI"
  64.  
  65. local enableButton = Instance.new("TextButton")
  66. enableButton.Parent = gui
  67. enableButton.Size = UDim2.new(0, 100, 0, 50)
  68. enableButton.Position = UDim2.new(0.25, 0, 0.4, 0)
  69. enableButton.Text = "Enable TPFlying"
  70. enableButton.FontSize = Enum.FontSize.Size24
  71. enableButton.TextColor3 = Color3.new(1, 1, 1)
  72. enableButton.BackgroundColor3 = Color3.new(0.5, 0.5, 0.5)
  73. enableButton.BorderSizePixel = 0
  74. enableButton.MouseButton1Click:Connect(enableFlying)
  75.  
  76. local disableButton = Instance.new("TextButton")
  77. disableButton.Parent = gui
  78. disableButton.Size = UDim2.new(0, 100, 0, 50)
  79. disableButton.Position = UDim2.new(0.65, 0, 0.4, 0)
  80. disableButton.Text = "Disable TPFlying"
  81. disableButton.FontSize = Enum.FontSize.Size24
  82. disableButton.TextColor3 = Color3.new(1, 1, 1)
  83. disableButton.BackgroundColor3 = Color3.new(0.5, 0.5, 0.5)
  84. disableButton.BorderSizePixel = 0
  85. disableButton.MouseButton1Click:Connect(disableFlying)
Advertisement
Comments
Add Comment
Please, Sign In to add comment
Advertisement