Advertisement
rrixh

fly toggleable

Sep 27th, 2023
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.93 KB | None | 0 0
  1. local fly = SsTitle:AddToggle("Fly (R15 Required)", false, function(toggle)
  2.    repeat
  3.        wait()
  4.    until game.Players.LocalPlayer and game.Players.LocalPlayer.Character and
  5.        game.Players.LocalPlayer.Character:findFirstChild("UpperTorso") and
  6.        game.Players.LocalPlayer.Character:findFirstChild("Humanoid")
  7.    local mouse = game.Players.LocalPlayer:GetMouse()
  8.    repeat
  9.        wait()
  10.    until mouse
  11.    local plr = game.Players.LocalPlayer
  12.    local UpperTorso = plr.Character.UpperTorso
  13.    local flying = false
  14.    local deb = true
  15.    local ctrl = {f = 0, b = 0, l = 0, r = 0}
  16.    local lastctrl = {f = 0, b = 0, l = 0, r = 0}
  17.    local maxspeed = 150
  18.    local speed = 0
  19.    
  20.    function Fly()
  21.        local bg = Instance.new("BodyGyro", UpperTorso)
  22.        bg.P = 9e4
  23.        bg.maxTorque = Vector3.new(9e9, 9e9, 9e9)
  24.        bg.cframe = UpperTorso.CFrame
  25.        local bv = Instance.new("BodyVelocity", UpperTorso)
  26.        bv.velocity = Vector3.new(0, 0.1, 0)
  27.        bv.maxForce = Vector3.new(9e9, 9e9, 9e9)
  28.        repeat
  29.            wait()
  30.            plr.Character.Humanoid.PlatformStand = true
  31.            if ctrl.l + ctrl.r ~= 0 or ctrl.f + ctrl.b ~= 0 then
  32.                speed = speed + .5 + (speed / maxspeed)
  33.                if speed > maxspeed then
  34.                    speed = maxspeed
  35.                end
  36.            elseif not (ctrl.l + ctrl.r ~= 0 or ctrl.f + ctrl.b ~= 0) and speed ~= 0 then
  37.                speed = speed - 1
  38.                if speed < 0 then
  39.                    speed = 0
  40.                end
  41.            end
  42.            if (ctrl.l + ctrl.r) ~= 0 or (ctrl.f + ctrl.b) ~= 0 then
  43.                bv.velocity =
  44.                    ((game.Workspace.CurrentCamera.CoordinateFrame.lookVector * (ctrl.f + ctrl.b)) +
  45.                    ((game.Workspace.CurrentCamera.CoordinateFrame *
  46.                        CFrame.new(ctrl.l + ctrl.r, (ctrl.f + ctrl.b) * .2, 0).p) -
  47.                        game.Workspace.CurrentCamera.CoordinateFrame.p)) *
  48.                    speed
  49.                lastctrl = {f = ctrl.f, b = ctrl.b, l = ctrl.l, r = ctrl.r}
  50.            elseif (ctrl.l + ctrl.r) == 0 and (ctrl.f + ctrl.b) == 0 and speed ~= 0 then
  51.                bv.velocity =
  52.                    ((game.Workspace.CurrentCamera.CoordinateFrame.lookVector * (lastctrl.f + lastctrl.b)) +
  53.                    ((game.Workspace.CurrentCamera.CoordinateFrame *
  54.                        CFrame.new(lastctrl.l + lastctrl.r, (lastctrl.f + lastctrl.b) * .2, 0).p) -
  55.                        game.Workspace.CurrentCamera.CoordinateFrame.p)) *
  56.                    speed
  57.            else
  58.                bv.velocity = Vector3.new(0, 0.1, 0)
  59.            end
  60.            bg.cframe =
  61.                game.Workspace.CurrentCamera.CoordinateFrame *
  62.                CFrame.Angles(-math.rad((ctrl.f + ctrl.b) * 50 * speed / maxspeed), 0, 0)
  63.        until not flying
  64.        ctrl = {f = 0, b = 0, l = 0, r = 0}
  65.        lastctrl = {f = 0, b = 0, l = 0, r = 0}
  66.        speed = 0
  67.        bg:Destroy()
  68.        bv:Destroy()
  69.        plr.Character.Humanoid.PlatformStand = false
  70.    end
  71.    mouse.KeyDown:connect(
  72.        function(key)
  73.            if toggle == false then
  74.                flying = false
  75.            end
  76.            if toggle == true then
  77.                flying = true
  78.                Fly()
  79.            end
  80.            elseif key:lower() == "w" then
  81.                ctrl.f = 1
  82.            elseif key:lower() == "s" then
  83.                ctrl.b = -1
  84.            elseif key:lower() == "a" then
  85.                ctrl.l = -1
  86.            elseif key:lower() == "d" then
  87.                ctrl.r = 1
  88.            end
  89.        end
  90.    )
  91.    mouse.KeyUp:connect(
  92.        function(key)
  93.            if key:lower() == "w" then
  94.                ctrl.f = 0
  95.            elseif key:lower() == "s" then
  96.                ctrl.b = 0
  97.            elseif key:lower() == "a" then
  98.                ctrl.l = 0
  99.            elseif key:lower() == "d" then
  100.                ctrl.r = 0
  101.            end
  102.        end
  103.    )
  104.    Fly()
  105.    
  106. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement