#static stamina drain per second

7 messages · Page 1 of 1 (latest)

woven oak
#

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)
#

anyway for me to get a static deltatime maybe that i can use in the stepped function?

night urchin
#
local rs = game:GetService("RunService")
local deltas = 0
rs.RenderStepped:Connect(function(delta)
    deltas += delta
    if deltas >= 1 then
        --drain stamina
        print(deltas)
        deltas = 0     
    end
end)
``` something like this
stark thicketBOT
#

studio** You are now Level 2! **studio

woven oak
#

could still use a little help, i want there to be a cooldown of 3 secs before stamina can start regenerating again as punishment when a player reaches 0 stamina and gets exhausted. I also want there to be a small cooldown for when the player still has stamina left and stops sprinting to regnerate stamina, this is to prevent players from gaining stamina too fast. I found the problem in my code but i have no clue how to fix it. Because the player still has all the requierements to start regenerating stamina the task.wait line just keeps repeating everytime the player gains some stamina. any work around for this problem?