Can anyone help me with my stamina issue?

Can anyone help me with the stamina script I made won’t let players stamina go up

if Sprinttoggled and Humanoid.MoveDirection.Magnitude > 0 then
		stamina = stamina - 1.3
	elseif Sprinttoggled == false and Humanoid.MoveDirection.Magnitude == 0  and Energyboost == false then
		stamina = stamina + 0.7
	end

That isn’t really enough to figure out your issue, but here are some thoughts:

  • What is Energyboost’s value when it doesn’t work? Could it be your forgot to update the Energyboost’s value whenever it should be false?
  • Does it not work when you don’t move?
  • Is the stamina really not going up? (when you print stamina does it change and go up?)
  • Do you have the code running in some loop?
  • Maybe you’ve forgotten to update the Sprinttoggled variable?
1 Like

The energy boost is mostly a item to make players stamina stay at 100 even if they are sprinting

The stamina will go down if sprinting it just does not go up

I don’t really use prints

I have a while wait do loop for the stamina, not the inputs

No i didn’t forget to update the sprinttoggled variable

Ok, try this:
When this code is run in the while loop, print Sprinttoggled, then print Humanod.MoveDirection.Magnitude, and then print Energyboost.
Printing is useful because you can check what the values of the variables are. By looking at what is print when you aren’t gaining any stamina, you can see what value is off/isn’t what it should be and then you can investigate it further.
Example:

print(`Sprint: {Sprinttoggled}`)
print(`MoveDirection magnitude: {Humanoid.MoveDirection.Magnitude}`)
print(`Energyboost: {Energyboost}`)
if Sprinttoggled and Humanoid.MoveDirection.Magnitude > 0 then
		stamina = stamina - 1.3
	elseif Sprinttoggled == false and Humanoid.MoveDirection.Magnitude == 0  and Energyboost == false then
		stamina = stamina + 0.7
	end

Please do this so we can easily debug the code and find out the issue

I just figured it out while you were typing I went back to Roblox studio and found out the issue when I implemented the energy boost thing that’s when the stamina broke

1 Like

Yeah, I was right after I removed the energy boost thing the stamina worked perfectly,
Now I have to figure out how to implement the energy boost without stamina breaking.

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