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

Stamina regeneration help the script wont work?

Ok so I made a stamina bar already and this is a separate local script in starterpack

wait(0.5)
local player = game.Players.LocalPlayer
local ldr = player:WaitForChild('ldr')
local stam = ldr:WaitForChild('Stamina')
local max = ldr:WaitForChild('MaxStamina')

if stam.Value > max.Value then
stam.Value = stam.Value + 1    
end

Anyways what I'm trying to do is if the stamina int value's value is under the max stamina int value's value than it will start regaining stamina but the script won't even play I know the stamina int value doesn't go up at all when I put it under the amount of the max stamina int value

1 comment

0

is the value a number value first? Scripts can only read number values if it's a number value(not always but it's the most simple way)

1 answer

✓ Accepted answer

I see your problem....

You're using the wrong relational operator in your if statement. Essentially, your if statement only will regen if the current stamina is greater than the max stamina. You want to change this to only regen if the current stamina is less than the max.

if stam.Value < max.Value then
	stam.Value = stam.Value + 1   
end

It would also be beneficial to put this if statement into a loop so that it constantly regenerates.

local howmuchtimeyouwanttowait = 1

while true do 
	if stam.Value < max.Value then
		stam.Value = stam.Value + 1   
	end
	wait(howmuchtimeyouwanttowait)
end

1 comment

0

Wow i cant believe i used greater than and not less than, thanks so much

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