Advertisement
coolden300

Untitled

Sep 1st, 2024
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.16 KB | Fixit | 0 0
  1. -- SpeedScriptRunner | Version 2.2 | Mobile Support Version 1.0 | Claasgreeneye
  2. -- Notice: This does not support Xbox Controllers! (yet...)
  3.  
  4. --< Services >--
  5. local Players: Players = game:GetService("Players")
  6. local TweenService: TweenService = game:GetService("TweenService")
  7. local UIS: UserInputService = game:GetService("UserInputService")
  8.  
  9. --< Constants >--
  10. local Player = Players.LocalPlayer
  11. local Character = Player.Character or Player.CharacterAdded:Wait()
  12. local Humanoid: Humanoid = Character:WaitForChild("Humanoid")
  13. local Camera: Camera = workspace.CurrentCamera
  14. local PlayerGui: PlayerGui = Player.PlayerGui
  15. local staminaBar: Frame = PlayerGui:WaitForChild("StatsGui").StaminaBar
  16. local DefaultFieldOFView = Camera.FieldOfView
  17. local DefaultWalkingSpeed = Humanoid.WalkSpeed
  18.  
  19. --< Variables >--
  20. local Speed: number = 24 -- How fast is the sprinting speed?
  21. local Key: Enum.KeyCode = Enum.KeyCode.LeftShift -- Activation Key
  22. local TweenSpeed: number = 0.4 -- How fast does the field of view change?
  23. local turnAccuracy = 10
  24. local mathCalcRange = 100
  25. local running = false
  26. local maxStamina = 100
  27. local minStaminaToRun = 10
  28. local currentStamina = maxStamina
  29.  
  30. --< Mobile Friendly Variables >--
  31. local MobileSupportUi: ScreenGui = PlayerGui:WaitForChild("MobileSprintSupport")
  32. MobileSupportUi.Enabled = false
  33.  
  34. --< Main Code >--
  35. local SprintingTween: Tween = TweenService:Create(Camera, TweenInfo.new(TweenSpeed), { FieldOfView = DefaultFieldOFView + (Speed / 2) })
  36. local WalkingTween: Tween = TweenService:Create(Camera, TweenInfo.new(TweenSpeed), { FieldOfView = DefaultFieldOFView })
  37.  
  38. Player.Character.Animate.walk.WalkAnim.AnimationId = "rbxassetid://90026095532911"
  39. Player.Character.Humanoid:ChangeState(Enum.HumanoidStateType.Landed)
  40.  
  41. local stamina = task.spawn(function()
  42.     while true do
  43.         if currentStamina > 0 and running then
  44.             currentStamina -= 0.5
  45.         elseif currentStamina <= 0 then
  46.             running = false
  47.             Humanoid.WalkSpeed = DefaultWalkingSpeed
  48.             WalkingTween:Play()
  49.         end
  50.        
  51.         if currentStamina < maxStamina and not running then
  52.             if Humanoid.MoveDirection.Magnitude == 0 then
  53.                 currentStamina += 0.25
  54.             else
  55.                 currentStamina += 0.1
  56.             end
  57.         end
  58.        
  59.         math.clamp(currentStamina, 0, maxStamina)
  60.         staminaBar.fill.Size = UDim2.fromScale(1, math.clamp(currentStamina / maxStamina,0,1))
  61.         staminaBar.fill.Position = UDim2.fromScale(0, 1-math.clamp(currentStamina / maxStamina,0,1))
  62.         staminaBar.fill.BackgroundColor3 = Color3.new(0.4, 0.4, 0.4):Lerp(Color3.new(Character.SystemColor.Value.X, Character.SystemColor.Value.Y, Character.SystemColor.Value.Z), math.clamp(currentStamina / maxStamina,0,1))                                
  63.        
  64.         wait(0.01)
  65.     end
  66. end)
  67.  
  68. task.spawn(function() -- ======================= PROBLEM LIES HERE I SUPPOSE
  69.     local changed = false
  70.     while true do
  71.         if running and not changed then
  72.             Player.Character.Animate.walk.WalkAnim.AnimationId = "rbxassetid://132508385298544"
  73.             Player.Character.Humanoid:ChangeState(Enum.HumanoidStateType.Landed)
  74.             changed = true
  75.         elseif not running and changed then
  76.             Player.Character.Animate.walk.WalkAnim.AnimationId = "rbxassetid://90026095532911"
  77.             Player.Character.Humanoid:ChangeState(Enum.HumanoidStateType.Landed)
  78.             changed = false
  79.         end
  80.         wait(0.1)
  81.     end
  82. end)
  83.  
  84.  
  85. if UIS.TouchEnabled and not UIS.GyroscopeEnabled then -- Mobile Friendly Code
  86.     MobileSupportUi.Enabled = true
  87.     local trigger: ImageButton = MobileSupportUi.Sprint
  88.     trigger.BackgroundColor3 = Color3.new(0.5, 0.5, 0.5)
  89.    
  90.     trigger.MouseEnter:Connect(function()
  91.         if Humanoid.MoveDirection.Magnitude == 0 then return end
  92.         if currentStamina <= minStaminaToRun then return end
  93.         running = true
  94.         trigger.BackgroundColor3 = Color3.new(1, 1, 0.5)
  95.         SprintingTween:Play()
  96.         Humanoid.WalkSpeed = Speed
  97.     end)
  98.    
  99.     trigger.MouseLeave:Connect(function()
  100.         running = false
  101.         trigger.BackgroundColor3 = Color3.new(0.5, 0.5, 0.5)
  102.         WalkingTween:Play()
  103.         Humanoid.WalkSpeed = DefaultWalkingSpeed
  104.     end)
  105.    
  106.  
  107. else -- Laptop and Desktop Friendly Code
  108.     UIS.InputBegan:Connect(function(Input: InputObject, Processed: boolean)
  109.         if not Processed then
  110.             if currentStamina <= minStaminaToRun then return end
  111.            
  112.             local lookDir = math.clamp(math.round(Character.PrimaryPart.CFrame.LookVector.X*turnAccuracy), -mathCalcRange, mathCalcRange)
  113.             local moveDir = math.clamp(math.round(Character.Humanoid.MoveDirection.X*turnAccuracy), -mathCalcRange, mathCalcRange)
  114.             --print(lookDir)
  115.             --print(moveDir)
  116.            
  117.             if lookDir ~= moveDir then
  118.                 running = false
  119.                 Humanoid.WalkSpeed = DefaultWalkingSpeed
  120.                 WalkingTween:Play()
  121.                 return
  122.             end
  123.             if Input.UserInputType == Enum.UserInputType.Keyboard and Input.KeyCode == Key then
  124.                 running = true
  125.                 Humanoid.WalkSpeed = Speed
  126.                 SprintingTween:Play()
  127.             end
  128.         end
  129.     end)
  130.  
  131.     UIS.InputEnded:Connect(function(Input: InputObject)
  132.         if Input.UserInputType == Enum.UserInputType.Keyboard and Input.KeyCode == Key then
  133.             running = false
  134.             Humanoid.WalkSpeed = DefaultWalkingSpeed
  135.             WalkingTween:Play()
  136.         end
  137.     end)
  138. end
  139.  
  140.  
  141.  
  142. --< Updating values when character is re-added >--
  143. Player.CharacterAdded:Connect(function(Char)
  144.     Character = Char
  145.     Humanoid = Character:WaitForChild("Humanoid")
  146. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement