title say it all, im working on a stamina system that drains a static amount of stamina per second of running and recharges a static amount when not running, out of ideas and cant find any help online. any help would be appreciated.
This is what i have so far
-- Services
local UIS = game:GetService("UserInputService")
local RNS = game:GetService("RunService")
-- Settings
local StaminaDrain = 5
local StaminaRecharge = 2
-- Booleans
local Sprinting = false
local SprintingHeld = false
local Exhausted = false
-- Script
local character = script.Parent
local Humanoid = character:WaitForChild("Humanoid")
local function sprint(active)
if active then
Humanoid.WalkSpeed = Humanoid:GetAttribute("SprintSpeed")
else
Humanoid.WalkSpeed = Humanoid:GetAttribute("BaseWalkSpeed")
end
Sprinting = active
end
UIS.InputBegan:Connect(function(input)
if input.KeyCode ~= Enum.KeyCode.LeftShift then return end
SprintingHeld = true
sprint(SprintingHeld)
end)
UIS.InputEnded:Connect(function(input)
if input.KeyCode ~= Enum.KeyCode.LeftShift then return end
SprintingHeld = false
sprint(SprintingHeld)
end)
** You are now Level 2! **