UIS.InputBegan:Connect(function(input, gpe)
if input.KeyCode == Enum.KeyCode.LeftShift and gpe == false then
sprinting = true
while sprinting and task.wait() do
if character.Humanoid.MoveDirection.Magnitude > 0 and sprinting and power > 0 then
Tween1:Play()
character.Humanoid.WalkSpeed = Run
power = power - 0.03
Bar.Size = UDim2.new(power/ 10, 0, 1, 0)
else
tween2:Play()
character.Humanoid.WalkSpeed = Walk
power = power + 0.01
Bar.Size = UDim2.new(power/ 10, 0, 1, 0)
end
end
end
end)
UIS.InputEnded:Connect(function(input, gpe)
if input.KeyCode == Enum.KeyCode.LeftShift and gpe == false then
sprinting = false
while sprinting == false and power < 10 and task.wait() do
tween2:Play()
character.Humanoid.WalkSpeed = Walk
power = power + 0.01
Bar.Size = UDim2.new(power/ 10, 0, 1, 0)
local UIS = game:GetService("UserInputService")
local Sprinting = false
local Key = Enum.KeyCode.LeftShift
local Humanoid = Character:WaitForChild("Humanoid")
function UpdateBarSize()
Bar.Size = UDim2.fromScale(Power * .1, 1)
end
function StartRun()
Tween1:Play()
Humanoid.WalkSpeed = Run
Power -= .03
end
function StartWalk()
Tween2:Play()
Humanoid.WalkSpeed = Walk
Power += .01
end
function InputBegan(Input: Enum.KeyCode, gpe: boolean)
if Input.KeyCode ~= Key or gpe or Sprinting then return end
Sprinting = true
end
function InputEnded(Input: Enum.KeyCode, gpe: boolean)
if Input.KeyCode ~= Key or gpe then return end
Sprinting = false
end
UIS.InputBegan:Connect(InputBegan)
UIS.InputEnded:Connect(InputEnded)
while true do
if Sprinting then
if Humanoid.MoveDirection.Magnitude > 0 and Power > 0 then
StartRun()
else
StartWalk()
end
elseif not Sprinting and Power < 10 then
StartWalk()
end
UpdateBarSize()
task.wait()
end