Advertisement
XZTablets

Don't Fall

Mar 31st, 2020
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.42 KB | None | 0 0
  1. local TweenService = game:GetService("TweenService")
  2. local Debris = game:GetService("Debris")
  3.  
  4. local Players = game:GetService("Players")
  5. local Player = Players.LocalPlayer
  6. local Character = Player.Character or Player.CharacterAdded:Wait()
  7. local HumanoidRootPart = Character.HumanoidRootPart
  8. local Humanoid = Character.Humanoid
  9.  
  10. local ActivationTime = 0.8
  11. local InstantTeleport = false
  12. local Enabled
  13. local LastTick
  14. local PreviousCFrames = {}
  15. local Info = TweenInfo.new(
  16.     0.8,
  17.     Enum.EasingStyle.Sine,
  18.     Enum.EasingDirection.Out,
  19.     0,
  20.     false,
  21.     0
  22. )
  23.  
  24. local function start()
  25.     while Enabled do
  26.         wait(0.05)
  27.         local HumanoidState = Humanoid:GetState()
  28.         if HumanoidState == Enum.HumanoidStateType.Freefall then
  29.             if not LastTick then
  30.                 LastTick = tick()
  31.             elseif LastTick then
  32.                 local NewTick = tick()
  33.                 if NewTick - LastTick > ActivationTime and HumanoidRootPart.CFrame.Position.Y < 0 and HumanoidState == Enum.HumanoidStateType.Freefall then
  34.                     for i = #PreviousCFrames,1,-1 do
  35.                         HumanoidRootPart.Anchored = true
  36.                         if not InstantTeleport then
  37.                             local RestorePosition = TweenService:Create(HumanoidRootPart, Info, {CFrame = PreviousCFrames[i]})
  38.                             RestorePosition:Play()
  39.                             RestorePosition.Completed:Wait()
  40.                         else
  41.                             HumanoidRootPart.CFrame = PreviousCFrames[i]
  42.                         end
  43.                         HumanoidRootPart.Anchored = false
  44.                         local NewState = Humanoid:GetState()
  45.                         if NewState ~= Enum.HumanoidStateType.Freefall then
  46.                             break
  47.                         end
  48.                     end
  49.                 end
  50.             end
  51.         elseif HumanoidState == Enum.HumanoidStateType.RunningNoPhysics or HumanoidState == Enum.HumanoidStateType.Landed or HumanoidState == Enum.HumanoidStateType.Running then
  52.             LastTick = nil
  53.             if #PreviousCFrames > 1000 then
  54.                 PreviousCFrames = {}
  55.             end
  56.             PreviousCFrames[#PreviousCFrames+1] = HumanoidRootPart.CFrame
  57.         elseif HumanoidState == Enum.HumanoidStateType.Jumping then
  58.             LastTick = nil
  59.         end
  60.     end
  61. end
  62.  
  63. local antifall = {}
  64.     function antifall.Enable()
  65.         Enabled = true
  66.         spawn(start)
  67.     end
  68.    
  69.     function antifall.Disable()
  70.         Enabled = false
  71.     end
  72.    
  73.     function antifall.InstantTeleport(value)
  74.         InstantTeleport = value
  75.     end
  76.    
  77.     function antifall.EditActivationTime(value)
  78.         ActivationTime = value
  79.     end
  80.    
  81.     function antifall.EditTweenTime(value)
  82.         Info = TweenInfo.new(
  83.             value,
  84.             Enum.EasingStyle.Sine,
  85.             Enum.EasingDirection.Out,
  86.             0,
  87.             false,
  88.             0)
  89.     end
  90. return antifall
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement