Sprint System (its changing the animation):
-- Services --
local CAS = game:GetService("ContextActionService")
local RunService = game:GetService("RunService")
local TweenService = game:GetService("TweenService")
local TweenServiceInfo = TweenInfo.new(3, Enum.EasingStyle.Linear, Enum.EasingDirection.In)
local SoundTweenInfo = TweenInfo.new(1.5, Enum.EasingStyle.Linear, Enum.EasingDirection.In)
-- Script Infos --
local player = game:GetService("Players").LocalPlayer
local character = player.Character
local humanoid = character:WaitForChild("Humanoid")
local cam = game.Workspace.Camera
local SFX = script["running man loop"]
local HearthBreakTween
local SoundTween
-- Settings --
local sprinting = false
local StaminaUsage = 0.02
local ReGainingStamina = 0.2
local lastSprint = 0
local reChargeTime = 4
local OverLoaded = false
local HeavyBreathing = false
-- Animation --
local Sprint = character.Animate.run.RunAnim
local SprintAnim = humanoid.Animator:LoadAnimation(Sprint)
cam.FieldOfView = 60
local StaminaEating = RunService.RenderStepped:Connect(function(delta)
local Stamina = humanoid:GetAttribute("Stamina")
local Sprintable = humanoid:GetAttribute("Sprintable")
if not Stamina and not Sprintable then return end
task.spawn(function()
if Stamina < 60 and sprinting then
if not cam:FindFirstChild("StaminaColorCorrection") then
local ColorCorrection = Instance.new("ColorCorrectionEffect", cam)
ColorCorrection.Name = "StaminaColorCorrection"
end
local ColorCorrection = cam.StaminaColorCorrection
if HearthBreakTween then
HearthBreakTween:Cancel()
end
if SoundTween then
SoundTween:Cancel()
end
HearthBreakTween = TweenService:Create(ColorCorrection, TweenServiceInfo, {
Contrast = 1,
TintColor = Color3.fromRGB(159, 62, 255)
})
SoundTween = TweenService:Create(SFX, SoundTweenInfo, {
Volume = 3
})
HearthBreakTween:Play()
SoundTween:Play()
HeavyBreathing = true
elseif Stamina > 30 and HeavyBreathing then
if not cam:FindFirstChild("StaminaColorCorrection") then
local ColorCorrection = Instance.new("ColorCorrectionEffect", cam)
ColorCorrection.Name = "StaminaColorCorrection"
end
local ColorCorrection = cam.StaminaColorCorrection
local oldColorCorrectionContrast = 0
local oldColorCorrectionTintColor = Color3.fromRGB(255, 255, 255)
if HearthBreakTween then
HearthBreakTween:Cancel()
end
if SoundTween then
SoundTween:Cancel()
end
HearthBreakTween = TweenService:Create(ColorCorrection, TweenServiceInfo, {
Contrast = oldColorCorrectionContrast,
TintColor = oldColorCorrectionTintColor
})
SoundTween = TweenService:Create(SFX, SoundTweenInfo, {
Volume = 0
})
SoundTween:Play()
HearthBreakTween:Play()
HeavyBreathing = false
end
end)
if Stamina < StaminaUsage and Sprintable then
sprinting = false
humanoid.WalkSpeed = humanoid:GetAttribute("NormalWalkSpeed")
SprintAnim:Stop()
TweenService:Create(cam, TweenServiceInfo, {FieldOfView = 60}):Play()
OverLoaded = true
end
if sprinting and Stamina > 0 and humanoid.MoveDirection.Magnitude > 0 and humanoid.WalkSpeed > 0 then
humanoid:SetAttribute("Stamina", Stamina - StaminaUsage)
lastSprint = tick()
else
if tick() - lastSprint > reChargeTime and Stamina < humanoid:GetAttribute("MaxStamina") then
humanoid:SetAttribute("Stamina", Stamina + ReGainingStamina)
OverLoaded = false
end
end
end)
local function sprint(actionName, inputState, inputType)
local Sprintable = humanoid:GetAttribute("Sprintable")
local Stamina = humanoid:GetAttribute("Stamina")
if not Sprintable then
character.HumanoidRootPart.Running.PlaybackSpeed = 0.7
TweenService:Create(cam, TweenServiceInfo, {FieldOfView = 60}):Play()
SprintAnim:Stop()
return
end
if humanoid.WalkSpeed <= 0 then return end
if inputState == Enum.UserInputState.Begin and humanoid.MoveDirection.Magnitude > 0 and Sprintable then
sprinting = true
elseif inputState == Enum.UserInputState.End then
sprinting = false
end
if sprinting and Stamina > StaminaUsage and Sprintable then
TweenService:Create(cam, TweenServiceInfo, {FieldOfView = 65}):Play()
humanoid.WalkSpeed = humanoid:GetAttribute("SprintingWalkSpeed")
SprintAnim:Play()
elseif Sprintable then
TweenService:Create(cam, TweenServiceInfo, {FieldOfView = 60}):Play()
humanoid.WalkSpeed = humanoid:GetAttribute("NormalWalkSpeed")
SprintAnim:Stop()
end
end
-- CAS's Bind's --
CAS:BindAction("Sprint", sprint, true, Enum.KeyCode.LeftShift)