Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

I have attempted to make a stamina system and for some reason it's random?

I have attempted to make a stamina system but the problem is that whenever I start the game and look at the output it goes negative and in a second it'd be -1000 and whenever you start running it'd go up there is no part of the script that would do this

so that means the amount of time of running will take longer to deplete stamina if you don't run edit: if your wondering why I have renderstepped, there's code that is not part of the issue

local timeyouahavebeenrunning = 0
RunService.RenderStepped:Connect(function()
	local stamina = 6


	if timeyouahavebeenrunning == stamina then
		camera.FieldOfView = 68
		humanoid.WalkSpeed = 14
		wait(6)
		timeyouahavebeenrunning = timeyouahavebeenrunning - timeyouahavebeenrunning
	elseif Userinputservice:IsKeyDown(Enum.KeyCode.LeftShift) or Userinputservice:IsKeyDown(Enum.KeyCode.RightShift) then

			camera.FieldOfView = 80
			humanoid.WalkSpeed = 23

			repeat 
				
				timeyouahavebeenrunning = timeyouahavebeenrunning + 1
				wait(1)
				
			until timeyouahavebeenrunning == 6
		else
			camera.FieldOfView = 70

			humanoid.WalkSpeed = 16

			repeat 
				timeyouahavebeenrunning = timeyouahavebeenrunning - 1
				wait(1)
				
			until Userinputservice:IsKeyDown(Enum.KeyCode.LeftShift)or Userinputservice:IsKeyDown(Enum.KeyCode.RightShift) or timeyouahavebeenrunning == 0

			end
		end)
	

1 answer

You need to add debounce so it doesn't repeat the loop many times rather than waiting.

2 comments

0

Either I did it wrong but didn't work, can you show me?

0

Plus, the waiting is meant for how long you can run, I want to run for 6 seconds

This discussion is preserved as it was. New answers, comments, and votes are closed.