Stamina regeneration

wait()

local maxStamina = script.Parent["StaminaRegen "].MaxStamina
local currentstamina = script.Parent["StaminaRegen "].CurrentStamina
local isRegen = false
local debounce = false
local running = script.Parent["StaminaRegen "].running

local Player = game.Players.LocalPlayer --local player
local Character = Player.Character --character
local Humanoid = Character:FindFirstChild("Humanoid") --finds the humanoid from the players character


while currentstamina.Value <= maxStamina.Value do
	if not running.Value then
		wait(0.5)
		print("Antonio Stupid")
	end
end



 
currentstamina.Changed:Connect(function()
	print("2")
	if not debounce then
		debounce = true
		print("3")
		if not isRegen and currentstamina.Value < maxStamina.Value then
			isRegen = true
			print("4")
		end
		debounce = true
	end
end)

local regenCo = coroutine.resume(coroutine.create(function()
	
	while true do wait(.5) -- how fast stamina will be regen
		if isRegen then
			currentstamina.Value += 1 -- how much stamina will be regen
			print("2")
			if currentstamina.Value >= maxStamina.Value then
				currentstamina.Value = maxStamina.Value
				isRegen = false
				print("3")
			end
		end
	end
end))

Okay, I have a script that should regenerate stamina if the character walks or stands. And if he’s running, then don’t touch stamina. The problem is that this script does not work. What to do? There are no errors.

P.S. I have a working script that when dash spends stamina. But the regeneration does not work


If anything, here’s where all the files are

1 Like

i dont think that you even changed the stamina in the loop\

I think they were more of less doing this to see if it printed out (aka debugging it)

@Dssall2 idk small thing but, have you tried removing the spaces where you call maxStamina, currentStamina at script.Parent["StaminaRegen "] maybe removing the space in the " " might help?