Else statement not working inside while loop

Hey, so I’m attempting to make a stamina regen script and originally is was going well, but I’ve made a combat tag that makes it so the stamina regen lowers when activated. I’ve been having trouble with this, as when I use an elseif to detect if the combat tag is found in the character, the while loop ignores it and never runs.

local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")

local nen = character:FindFirstChild("Nen") -- numbervalue/stamina with a value of 100

local enabled = 0.04 -- combat tag regen
local disabled = 0.1-- out-of-combat regen

while wait() do
	
	if nen.Value < 100 then

		local activate = character:FindFirstChild("Activate") -- combat tag
		
		if activate then
			
			nen.Value += enabled
			print(enabled)
		else
			
			nen.Value += disabled
			print(disabled)
		end
	end
end

Here, it’d only run the disabled regen and never run the enabled regen when Activate is inserted into the character. I can slightly understand why, but not sure of a solution I could take to solve this issue. Any help is appreciated!

First I’d recommend doing a while true do and then putting a wait() inside of the loop. Second, what happens when nen.Value == 100? Your script only checks if it’s less than 100.

Regens stops when the value is equal to 100.

I changed it to while true do and all, but still no luck.

while true do
	
	if nen.Value < 100 then

		local activate = character:FindFirstChild("Activate")
		
		if activate then
			
			nen.Value += enabled
			print(enabled)
		else
			
			nen.Value += disabled
			print(disabled)
		end
	end
	
	
	wait()
end

Try doing an if statement after the else statement.

		else
			if nen.Value > 100 then
			nen.Value += disabled
			print(disabled)
            end
		end
	end

Also you should add wait() after the “while true do” loop.

Tried it, but still no luck.

I don’t know if you meant nen.Value > 100 or nen.Value < 100, but nen.Value > 100 stopped the regen entirely anyway.

while true do
	
	wait()

	if nen.Value < 100 then

		local activate = character:FindFirstChild("Activate")

		if activate then

			nen.Value += enabled
			print(enabled)
		else
			if nen.Value < 100 then
				nen.Value += disabled
				print(disabled)
			end
		end
	end	
end