Advertisement
DaDogeDevelopment

How to make a fly button

Nov 24th, 2022 (edited)
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.34 KB | None | 0 0
  1. -- Local script inside of your button
  2.  
  3. local speed = 50
  4.  
  5. repeat wait() until game.Players.LocalPlayer.Character
  6.  
  7. local button = script.Parent.Parent.FlyButton
  8. local plr = game.Players.LocalPlayer
  9. local char = plr.Character
  10. local hum = char:WaitForChild("Humanoid")
  11. local Torso = char:WaitForChild("HumanoidRootPart")
  12. local Mouse = plr:GetMouse()
  13. local toggle = false
  14.  
  15. -- function
  16. script.Parent.MouseButton1Click:Connect(function()
  17.     if script.Parent.MouseButton1Click then
  18.         if toggle == false then
  19.             toggle = true
  20.             local Anim = Instance.new("Animation")
  21.             Anim.AnimationId = "rbxassetid://9665206880"-- Animation while flying
  22.             local PlayAnim = hum:LoadAnimation(Anim)
  23.             PlayAnim:Play()
  24.             local BV = Instance.new("BodyVelocity",Torso)
  25.             BV.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
  26.             while toggle == true do
  27.                 BV.Velocity = Mouse.Hit.LookVector*speed
  28.                 wait()
  29.             end
  30.         end
  31.         if toggle == true then
  32.             toggle = false
  33.             Torso:FindFirstChildOfClass("BodyVelocity"):Destroy()
  34.             local tracks = hum:GetPlayingAnimationTracks()
  35.             for i, stopTracks in pairs(tracks) do
  36.                 stopTracks:Stop()
  37.             end
  38.             local Anim = Instance.new("Animation")
  39.             Anim.AnimationId = "rbxassetid://0" -- Animation while idle (I recomend to not change this)
  40.             local PlayAnim = hum:LoadAnimation(Anim)
  41.             PlayAnim:Play()
  42.         end
  43.     end
  44. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement