local StaminaManager = require(script.Parent:WaitForChild("StaminaModule"))

local defaultSpeed = 16
local sprintSpeed = 22
local normalFov = 70
local sprintFov = 80
local crouchFov = 65
local crouchSpeed = 8
local normalSpeed = 16
local crouchHeight = 1.5
local normalHeight = 2
local staminaDrainRate = 17

local Services = setmetatable({}, {
	__index = function(Self, Index)
		local NewService = game:GetService(Index)
		if NewService then
			Self[Index] = NewService
		end
		return NewService
	end
})

local UserInputService = Services.UserInputService
local TweenService = Services.TweenService
local RunService = Services.RunService
local Players = Services.Players
local ReplicatedStorage = Services.ReplicatedStorage

local sprintKey = Enum.KeyCode.LeftShift
local crouchKey = Enum.KeyCode.C
local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
local Camera = workspace.CurrentCamera
local sprintAnim = ReplicatedStorage:WaitForChild("Animations"):WaitForChild("Player"):WaitForChild("SprintAnim")
local animTrack = Humanoid:LoadAnimation(sprintAnim)
local healthBar = Player.PlayerGui:WaitForChild("StaminaAndHealthBar"):WaitForChild("Frame"):WaitForChild("HealthBar"):WaitForChild("Bar")
local staminaBar = Player.PlayerGui:WaitForChild("StaminaAndHealthBar"):WaitForChild("Frame"):WaitForChild("StaminaBar"):WaitForChild("Bar")
local shiftPressed = false
local movementKeysPressed = {}
local sprinting = false
local isCrouching = false
local isMoving = false
local movementKeys = {Enum.KeyCode.W, Enum.KeyCode.A, Enum.KeyCode.S, Enum.KeyCode.D}

local function tweenFov(duration, fov)
	local tween = TweenService:Create(Camera, TweenInfo.new(duration, Enum.EasingStyle.Quad), { FieldOfView = fov })
	tween:Play()
	tween.Completed:Wait()
	tween:Destroy()
end

local function tweenStaminaBar()
	local stamina = StaminaManager.GetStamina()
	local tween = TweenService:Create(staminaBar, TweenInfo.new(0.25, Enum.EasingStyle.Quad), { Size = UDim2.new(stamina / StaminaManager.maxStamina, 0, 1, 0) })
	tween:Play()
end

local function startSprinting()
	if not sprinting and StaminaManager.GetStamina() > 0 and not isCrouching then
		sprinting = true
		StaminaManager.ReduceStamina(staminaDrainRate * RunService.RenderStepped:Wait())
		Humanoid.WalkSpeed = sprintSpeed
		if Humanoid:GetState() ~= Enum.HumanoidStateType.Freefall then
			animTrack:Play()
		end 
		tweenFov(0.25, sprintFov)
		tweenStaminaBar()
	end
end

local function stopSprinting()
	if sprinting then
		sprinting = false
		Humanoid.WalkSpeed = defaultSpeed
		animTrack:Stop()
		tweenFov(0.25, normalFov)
		tweenStaminaBar()
	end
end

local function crouch()
	if not isCrouching and not sprinting then
		if animTrack.IsPlaying then
			animTrack:Stop()
		end
		isCrouching = true
		Humanoid.WalkSpeed = crouchSpeed
		HumanoidRootPart.Size = Vector3.new(HumanoidRootPart.Size.X, crouchHeight, HumanoidRootPart.Size.Z)
		tweenFov(0.25, crouchFov)
	end
end

local function stand()
	if isCrouching then
		isCrouching = false
		Humanoid.WalkSpeed = normalSpeed
		HumanoidRootPart.Size = Vector3.new(HumanoidRootPart.Size.X, normalHeight, HumanoidRootPart.Size.Z)
		tweenFov(0.25, normalFov)
	end
end

Character.Humanoid:GetPropertyChangedSignal("Health"):Connect(function()
	healthBar.Size = UDim2.new(Character.Humanoid.Health / 100, 0, 1, 0)
end)

local isSliding = false

local function startSliding()
	if isSliding then return end
	isSliding = true
	sprinting = false

	tweenFov(0.25, sprintFov)
end

local function stopSliding()
	if not isSliding then return end
	isSliding = false

	tweenFov(0.25, normalFov)
end

UserInputService.InputBegan:Connect(function(input, processed)
	if processed then return end
	if Humanoid.Health == 0 then return end
	if input.KeyCode == sprintKey then
		shiftPressed = true
		if next(movementKeysPressed) ~= nil then
			startSprinting()
		end

	elseif table.find(movementKeys, input.KeyCode) then
		movementKeysPressed[input.KeyCode] = true
		if shiftPressed and StaminaManager.GetStamina() > 0 and not isCrouching then
			startSprinting()
		end

	elseif input.KeyCode == crouchKey then
		if sprinting then
			startSliding()
		else
			crouch()
		end
	end
end)

UserInputService.InputEnded:Connect(function(input)
	if Humanoid.Health == 0 then return end
	if input.KeyCode == sprintKey then
		shiftPressed = false
		stopSprinting()
	elseif table.find(movementKeys, input.KeyCode) then
		movementKeysPressed[input.KeyCode] = nil
		if next(movementKeysPressed) == nil then
			stopSprinting()
		end
	elseif input.KeyCode == crouchKey and not sprinting then
		stand()
	end
end)

RunService.RenderStepped:Connect(function(deltaTime)
	if sprinting then
		if not StaminaManager.ReduceStamina(staminaDrainRate * deltaTime) then
			stopSprinting()
		end
	end
	tweenStaminaBar()
end)

Humanoid:GetPropertyChangedSignal("MoveDirection"):Connect(function()
	isMoving = Humanoid.MoveDirection.Magnitude > 0
end)

local anim = ReplicatedStorage.Animations.Player.Land
local playAnim = script.Parent.Parent.Humanoid:LoadAnimation(anim)

Humanoid.StateChanged:Connect(function(oldState, newState)
	if newState == Enum.HumanoidStateType.Freefall then
		animTrack:Stop()
	elseif newState == Enum.HumanoidStateType.Landed then
		animTrack:Stop()
		playAnim:Play()
		playAnim.Stopped:Wait()
		if sprinting then
			animTrack:Play()
		end
	end
end)

-- Dash functionality from script2
local BV = Instance.new("BodyVelocity")

local Settings = {
	Lifetime = 0.15,
	DashVelocity = 55,
	Cooldown = 3,
	DashStaminaCost = 20,
}

local Keycodes = {
	[Enum.KeyCode.E] = true,
	[Enum.KeyCode.ButtonL1] = true,
}

local Animations = {
	Forward = Humanoid:LoadAnimation(ReplicatedStorage:WaitForChild("Animations"):WaitForChild("Player"):WaitForChild("FrontDash")),
	Backward = Humanoid:LoadAnimation(ReplicatedStorage:WaitForChild("Animations"):WaitForChild("Player"):WaitForChild("BackDash")),
	Left = Humanoid:LoadAnimation(ReplicatedStorage:WaitForChild("Animations"):WaitForChild("Player"):WaitForChild("LeftDash")),
	Right = Humanoid:LoadAnimation(ReplicatedStorage:WaitForChild("Animations"):WaitForChild("Player"):WaitForChild("RightDash")),
}

local MovementKeys = {
	[Enum.KeyCode.W] = "Forward",
	[Enum.KeyCode.A] = "Left",
	[Enum.KeyCode.S] = "Backward",
	[Enum.KeyCode.D] = "Right",
}

local lastStaminaUseTime = 0

local function playDashAnimation()
	local direction
	for key, anim in pairs(MovementKeys) do
		if UserInputService:IsKeyDown(key) then
			direction = anim
			break
		end
	end

	if direction then
		Animations[direction]:Play()
	end
end

local function dash()
	local Now = workspace:GetServerTimeNow()
	local DashCooldown = Character:GetAttribute("DashCooldown") or 0
	if DashCooldown > Now or StaminaManager.GetStamina() < Settings.DashStaminaCost then
		return
	end

	Character:SetAttribute("DashCooldown", Now + Settings.Cooldown)

	StaminaManager.ReduceStamina(Settings.DashStaminaCost)
	lastStaminaUseTime = tick()

	local NewBV = BV:Clone()
	NewBV.MaxForce = Vector3.new(1e5, 1e5, 1e5)
	NewBV.P = 1250

	local Direction = Humanoid.MoveDirection
	if Direction.Magnitude == 0 then
		Direction = HumanoidRootPart.CFrame.LookVector
	end
	local CamP0 = Camera.CFrame.LookVector
	local RelativeDirection = CFrame.lookAt(CamP0, CamP0 + Direction).LookVector

	local currentYVelocity = HumanoidRootPart.Velocity.Y / 2
	NewBV.Velocity = Vector3.new(RelativeDirection.X, 0, RelativeDirection.Z) * Settings.DashVelocity + Vector3.new(0, currentYVelocity, 0)
	NewBV.Parent = HumanoidRootPart
	playDashAnimation()
	task.delay(Settings.Lifetime, function()
		NewBV:Destroy()
	end)
end

UserInputService.InputBegan:Connect(function(InputObject, SunkInput)
	if SunkInput then return end
	if not Keycodes[InputObject.KeyCode] then return end
	if Humanoid.Health == 0 then return end
	dash()
end)


there is some rendundant parts of the script. remove the redundancy.