Energy bar not refilling

Think I now have the record for most simple problems I cant solve on my own lol, any way this time I made a VERY simple few lines of code, whenever the player stops running and their speed returns to their original speed a while loop will start giving them +1 energy every second, it works the first time but if you start running again then stop, it stops working. Absolutely no bugs or errors.

anything with .Value is an intValue.

local script

while Humanoid.WalkSpeed == 30 or Humanoid.WalkSpeed == 16 do
	wait(1)
	if Energy.Value < 100 or VampireEnergy.Value < 100 then
	EnergyDown:FireServer(Energy,VampireEnergy, Vampire, Human)
	end
end

server script

EnergyDown.OnServerEvent:Connect(function(Player, Energy, VampireEnergy, Vampire,Human)
	if Vampire.Value == true then
		VampireEnergy.Value += 1
	elseif Human.Value == true then
		Energy.Value += 1
	end
end)
1 Like

which line checks if the player is running? is it the while conditional? I would use MoveDirection (humanoid property) to know or maybe the humanoid’s current state

to debug i would add a print inside the while loop, outside the if statement to see if it’s even running (because WalkSpeed being anything other than 30 or 16 would stop it)

also you said

but it looks like Vampire and Human are BoolValues

This loop terminates when both conditions are false. If you want for it to run forever, you should do something like:

while task.wait() do
	if Humanoid.WalkSpeed == 30 or Humanoid.WalkSpeed == 16 do
		if Energy.Value < 100 or VampireEnergy.Value < 100 then
			EnergyDown:FireServer(Energy,VampireEnergy, Vampire, Human)
		end
	end  
end
1 Like

Sorry about that, forgot about them, yes they are.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.