Advertisement
Illous

Untitled

Mar 20th, 2023 (edited)
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.43 KB | Help | 0 0
  1. local player = game:GetService("Players").LocalPlayer
  2. local UserInputService = game:GetService("UserInputService")
  3. local Blur = Instance.new("BlurEffect")
  4. local MaxSprint = 100
  5. local SprintDepletion = 0.5
  6. local SprintRegeneration = 0.1
  7. local Sprinting = false
  8. local sprintValue = MaxSprint
  9.  
  10. Blur.Parent = game:GetService("Lighting")
  11.  
  12. local ScreenGui = Instance.new("ScreenGui")
  13. ScreenGui.Parent = player.PlayerGui
  14.  
  15. local SprintBar = Instance.new("Frame")
  16. SprintBar.Parent = ScreenGui
  17. SprintBar.Size = UDim2.new(0.8, 0, 0, 10)
  18. SprintBar.Position = UDim2.new(0.1, 0, 0.9, 0)
  19. SprintBar.BackgroundColor3 = Color3.fromRGB(0, 100, 0)
  20. SprintBar.BorderColor3 = Color3.fromRGB(0, 0, 0)
  21. SprintBar.BorderSizePixel = 1
  22. SprintBar.ZIndex = 10
  23.  
  24. local SprintBarOverlay = Instance.new("Frame")
  25. SprintBarOverlay.Parent = SprintBar
  26. SprintBarOverlay.Size = UDim2.new(1, 0, 1, 0)
  27. SprintBarOverlay.BackgroundColor3 = Color3.fromRGB(0, 255, 0)
  28. SprintBarOverlay.BorderSizePixel = 0
  29. SprintBarOverlay.ZIndex = 9
  30.  
  31. local function UpdateSprintBar()
  32.     local sprintPercentage = sprintValue / MaxSprint
  33.     local depletedColor = Color3.fromRGB(200, 255, 200)
  34.     local normalColor = Color3.fromRGB(0, 255, 0)
  35.     SprintBarOverlay.Size = UDim2.new(sprintPercentage, 0, 1, 0)
  36.     SprintBarOverlay.BackgroundColor3 = depletedColor:lerp(normalColor, sprintPercentage)
  37.     if sprintPercentage == 0 then
  38.         Blur.Enabled = true
  39.         player.Character.Humanoid.WalkSpeed = 16
  40.     else
  41.         Blur.Enabled = false
  42.     end
  43. end
  44.  
  45. local function StartSprinting()
  46.     if sprintValue > 0 and not Sprinting then
  47.         Sprinting = true
  48.         player.Character.Humanoid.WalkSpeed = 32
  49.         UpdateSprintBar()
  50.     end
  51. end
  52.  
  53. local function StopSprinting()
  54.     if Sprinting then
  55.         Sprinting = false
  56.         player.Character.Humanoid.WalkSpeed = 16
  57.         UpdateSprintBar()
  58.     end
  59. end
  60.  
  61. UserInputService.InputBegan:Connect(function(input, gameProcessed)
  62.     if not gameProcessed and input.KeyCode == Enum.KeyCode.LeftShift then
  63.         StartSprinting()
  64.     end
  65. end)
  66.  
  67. UserInputService.InputEnded:Connect(function(input, gameProcessed)
  68.     if not gameProcessed and input.KeyCode == Enum.KeyCode.LeftShift then
  69.         StopSprinting()
  70.     end
  71. end)
  72.  
  73. while true do
  74.     wait(0.1)
  75.     if Sprinting then
  76.         sprintValue = math.max(0, sprintValue - SprintDepletion)
  77.         UpdateSprintBar()
  78.         if sprintValue <= 0 then
  79.             StopSprinting()
  80.         end
  81.     elseif sprintValue < MaxSprint then
  82.         sprintValue = math.min(MaxSprint, sprintValue + SprintRegeneration)
  83.         UpdateSprintBar()
  84.     end
  85. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement