Advertisement
ShinjitaroSoul

For Alow Alew Eyes Only

Apr 2nd, 2024
589
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.33 KB | None | 0 0
  1. local Players = game:GetService("Players")
  2. local RunServince = game:GetService("RunService")
  3. local UserInputService = game:GetService("UserInputService")
  4. local ReplicatedStorage = game:GetService("ReplicatedStorage")
  5.  
  6. local AnimationModule = require(ReplicatedStorage:WaitForChild("Animations"))
  7. local Unbinds = require(script:WaitForChild("Unbinds"))
  8. local ZoomDistance = require(script:WaitForChild("ZoomDistance"))
  9.  
  10. local Data = {}
  11. Data.LocalPlayer = Players.LocalPlayer
  12. Data.Character = Data.LocalPlayer.Character or Data.LocalPlayer.CharacterAdded:Wait()
  13. Data.Humanoid = Data.Character:WaitForChild("Humanoid") :: Humanoid
  14. Data.Animator = Data.Humanoid:WaitForChild("Animator") :: Animator
  15. Data.AnimationTracks = AnimationModule.GetAnimations(Data.Animator) :: AnimationModule.AnimPack
  16. Data.MovementTracks = nil
  17.  
  18.  
  19. Data.Humanoid.JumpHeight = 0
  20. Data.Humanoid.JumpPower = 0
  21.  
  22. Data.TrackData = {
  23.     [Data.AnimationTracks.Crouch.Moving] = 8
  24. }
  25.  
  26. Data.CurrentMovingSpeed = 0
  27. Data.BaseSpeed = 12
  28. Data.SpeedModifiers = {}
  29.  
  30. Data.States = {}
  31.  
  32. Data.States.Crouching = {}
  33. Data.States.Crouching.Enter = function()
  34.     Data.SpeedModifiers.Crouch = -6
  35.    
  36.     if Data.MovementTracks then
  37.         local OldTracks = Data.MovementTracks
  38.        
  39.         for i, v in OldTracks do
  40.             v:Stop()
  41.         end
  42.        
  43.         Data.MovementTracks = nil
  44.     end
  45.  
  46.    
  47.     Data.MovementTracks = Data.AnimationTracks.Crouch
  48.        
  49. end
  50.  
  51. Data.States.Crouching.Exit = function()
  52.     Data.SpeedModifiers.Crouch = nil
  53.    
  54.     local CrouchTracks = Data.MovementTracks
  55.    
  56.     Data.MovementTracks = nil
  57.    
  58.     for i, v in CrouchTracks do
  59.         v:Stop()
  60.     end
  61.    
  62. end
  63.  
  64. Data.States.Sprinting = {}
  65. Data.States.Sprinting.Enter = function()
  66.     Data.SpeedModifiers.Sprint = 8
  67. end
  68. Data.States.Sprinting.Exit = function()
  69.     Data.SpeedModifiers.Sprint = nil
  70. end
  71.  
  72.  
  73. local function GetSpeedModifier()
  74.     local sum = 0
  75.    
  76.     for i, v in Data.SpeedModifiers do
  77.         sum += v
  78.     end
  79.    
  80.     return sum
  81. end
  82.  
  83. Data.Humanoid.Running:Connect(function(Speed)
  84.     Data.CurrentMovingSpeed = Speed
  85. end)
  86.  
  87. RunServince.RenderStepped:Connect(function()
  88.     local SpeedModifier = GetSpeedModifier()
  89.     local CurrentSpeed = Data.BaseSpeed + SpeedModifier
  90.    
  91.     Data.Humanoid.WalkSpeed = CurrentSpeed
  92.    
  93.     if Data.MovementTracks then
  94.         if Data.Humanoid.MoveDirection.Magnitude > 0 then
  95.             if not Data.MovementTracks.Moving.IsPlaying then
  96.                 Data.MovementTracks.Moving:Play()
  97.             end
  98.            
  99.             if Data.MovementTracks.Idle.IsPlaying then
  100.                 Data.MovementTracks.Idle:Stop()
  101.             end
  102.            
  103.             Data.MovementTracks.Moving:AdjustSpeed(Data.CurrentMovingSpeed / Data.TrackData[Data.MovementTracks.Moving])
  104.         else
  105.             if Data.MovementTracks.Moving.IsPlaying then
  106.                 Data.MovementTracks.Moving:Stop()
  107.             end
  108.            
  109.             if not Data.MovementTracks.Idle.IsPlaying then
  110.                 Data.MovementTracks.Idle:Play()
  111.             end
  112.         end
  113.     end
  114. end)
  115.  
  116. local function ExitAllStates()
  117.     for i, v in Data.States do
  118.         v[Data.Character] = nil
  119.         v.Exit()
  120.     end
  121. end
  122.  
  123. local function ToggleCrouch()
  124.     if Data.States.Crouching[Data.Character] then
  125.         Data.States.Crouching[Data.Character] = nil
  126.         Data.States.Crouching.Exit()
  127.     else
  128.         Data.States.Crouching[Data.Character] = true
  129.         Data.States.Crouching.Enter()
  130.     end
  131. end
  132.  
  133.  
  134.  
  135. local Inputs = {
  136.     -- Crouch
  137.     [Enum.KeyCode.LeftControl] = ToggleCrouch,
  138.     [Enum.KeyCode.ButtonL1] = ToggleCrouch,
  139.    
  140.     -- Sprint
  141.     [Enum.KeyCode.LeftShift] = Data.States.Sprinting.Enter,
  142.     [Enum.KeyCode.ButtonL1] = Data.States.Sprinting.Enter,
  143. }
  144.  
  145. local ReleaseInput = {
  146.     -- Sprint
  147.     [Enum.KeyCode.LeftShift] = Data.States.Sprinting.Exit,
  148.     [Enum.KeyCode.ButtonL1] = Data.States.Sprinting.Exit,
  149. }
  150.  
  151. UserInputService.InputBegan:Connect(function(Input, Gme)
  152.     if Gme then return end
  153.    
  154.     local Action = Inputs[Input.KeyCode]
  155.    
  156.     if not Action then return end
  157.    
  158.     Action()
  159. end)
  160.  
  161. UserInputService.InputEnded:Connect(function(Input, Gme)
  162.     if Gme then return end
  163.    
  164.     local Action = ReleaseInput[Input.KeyCode]
  165.    
  166.     if not Action then return end
  167.    
  168.     Action()
  169. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement