Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- SpeedScriptRunner | Version 2.2 | Mobile Support Version 1.0 | Claasgreeneye
- -- Notice: This does not support Xbox Controllers! (yet...)
- --< Services >--
- local Players: Players = game:GetService("Players")
- local TweenService: TweenService = game:GetService("TweenService")
- local UIS: UserInputService = game:GetService("UserInputService")
- --< Constants >--
- local Player = Players.LocalPlayer
- local Character = Player.Character or Player.CharacterAdded:Wait()
- local Humanoid: Humanoid = Character:WaitForChild("Humanoid")
- local Camera: Camera = workspace.CurrentCamera
- local PlayerGui: PlayerGui = Player.PlayerGui
- local staminaBar: Frame = PlayerGui:WaitForChild("StatsGui").StaminaBar
- local DefaultFieldOFView = Camera.FieldOfView
- local DefaultWalkingSpeed = Humanoid.WalkSpeed
- --< Variables >--
- local Speed: number = 24 -- How fast is the sprinting speed?
- local Key: Enum.KeyCode = Enum.KeyCode.LeftShift -- Activation Key
- local TweenSpeed: number = 0.4 -- How fast does the field of view change?
- local turnAccuracy = 10
- local mathCalcRange = 100
- local running = false
- local maxStamina = 100
- local minStaminaToRun = 10
- local currentStamina = maxStamina
- --< Mobile Friendly Variables >--
- local MobileSupportUi: ScreenGui = PlayerGui:WaitForChild("MobileSprintSupport")
- MobileSupportUi.Enabled = false
- --< Main Code >--
- local SprintingTween: Tween = TweenService:Create(Camera, TweenInfo.new(TweenSpeed), { FieldOfView = DefaultFieldOFView + (Speed / 2) })
- local WalkingTween: Tween = TweenService:Create(Camera, TweenInfo.new(TweenSpeed), { FieldOfView = DefaultFieldOFView })
- Player.Character.Animate.walk.WalkAnim.AnimationId = "rbxassetid://90026095532911"
- Player.Character.Humanoid:ChangeState(Enum.HumanoidStateType.Landed)
- local stamina = task.spawn(function()
- while true do
- if currentStamina > 0 and running then
- currentStamina -= 0.5
- elseif currentStamina <= 0 then
- running = false
- Humanoid.WalkSpeed = DefaultWalkingSpeed
- WalkingTween:Play()
- end
- if currentStamina < maxStamina and not running then
- if Humanoid.MoveDirection.Magnitude == 0 then
- currentStamina += 0.25
- else
- currentStamina += 0.1
- end
- end
- math.clamp(currentStamina, 0, maxStamina)
- staminaBar.fill.Size = UDim2.fromScale(1, math.clamp(currentStamina / maxStamina,0,1))
- staminaBar.fill.Position = UDim2.fromScale(0, 1-math.clamp(currentStamina / maxStamina,0,1))
- 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))
- wait(0.01)
- end
- end)
- task.spawn(function() -- ======================= PROBLEM LIES HERE I SUPPOSE
- local changed = false
- while true do
- if running and not changed then
- Player.Character.Animate.walk.WalkAnim.AnimationId = "rbxassetid://132508385298544"
- Player.Character.Humanoid:ChangeState(Enum.HumanoidStateType.Landed)
- changed = true
- elseif not running and changed then
- Player.Character.Animate.walk.WalkAnim.AnimationId = "rbxassetid://90026095532911"
- Player.Character.Humanoid:ChangeState(Enum.HumanoidStateType.Landed)
- changed = false
- end
- wait(0.1)
- end
- end)
- if UIS.TouchEnabled and not UIS.GyroscopeEnabled then -- Mobile Friendly Code
- MobileSupportUi.Enabled = true
- local trigger: ImageButton = MobileSupportUi.Sprint
- trigger.BackgroundColor3 = Color3.new(0.5, 0.5, 0.5)
- trigger.MouseEnter:Connect(function()
- if Humanoid.MoveDirection.Magnitude == 0 then return end
- if currentStamina <= minStaminaToRun then return end
- running = true
- trigger.BackgroundColor3 = Color3.new(1, 1, 0.5)
- SprintingTween:Play()
- Humanoid.WalkSpeed = Speed
- end)
- trigger.MouseLeave:Connect(function()
- running = false
- trigger.BackgroundColor3 = Color3.new(0.5, 0.5, 0.5)
- WalkingTween:Play()
- Humanoid.WalkSpeed = DefaultWalkingSpeed
- end)
- else -- Laptop and Desktop Friendly Code
- UIS.InputBegan:Connect(function(Input: InputObject, Processed: boolean)
- if not Processed then
- if currentStamina <= minStaminaToRun then return end
- local lookDir = math.clamp(math.round(Character.PrimaryPart.CFrame.LookVector.X*turnAccuracy), -mathCalcRange, mathCalcRange)
- local moveDir = math.clamp(math.round(Character.Humanoid.MoveDirection.X*turnAccuracy), -mathCalcRange, mathCalcRange)
- --print(lookDir)
- --print(moveDir)
- if lookDir ~= moveDir then
- running = false
- Humanoid.WalkSpeed = DefaultWalkingSpeed
- WalkingTween:Play()
- return
- end
- if Input.UserInputType == Enum.UserInputType.Keyboard and Input.KeyCode == Key then
- running = true
- Humanoid.WalkSpeed = Speed
- SprintingTween:Play()
- end
- end
- end)
- UIS.InputEnded:Connect(function(Input: InputObject)
- if Input.UserInputType == Enum.UserInputType.Keyboard and Input.KeyCode == Key then
- running = false
- Humanoid.WalkSpeed = DefaultWalkingSpeed
- WalkingTween:Play()
- end
- end)
- end
- --< Updating values when character is re-added >--
- Player.CharacterAdded:Connect(function(Char)
- Character = Char
- Humanoid = Character:WaitForChild("Humanoid")
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement