#Stamina starts tripping after exhausted is over

15 messages · Page 1 of 1 (latest)

polar valley
#

as what did you define dt

whole herald
#

i dont think i defined it as anything

polar valley
#

so its 0 always

#

so you say stamina + 0 every time then?

whole herald
#

no sorry dt is for delatime so its staminaDrain/stamineRecharge * deltatime

frigid quailBOT
#

studio** You are now Level 1! **studio

whole herald
#

drain works fine

#

its just as soon as i stop sprinting it spasses out for some time and then starts regenerating normally

#

and at 0 stamina it doesnt regenerate at all it just gets stuck on the output i showed

polar valley
#

can you just print out this: print(staminaRecharge * dt)
right above this line
Humanoid:SetAttribute("Stamina", stamina + (staminaRecharge * dt))

i wanna see what that outputs the value that gets added to stamina

whole herald
polar valley
#

i see your error i think

#
UIS.InputBegan:Connect(function(input)
    if input.KeyCode ~= Enum.KeyCode.LeftShift then return end
    isSprinting = true
    sprint(isSprinting)
end)

in this part stop the user from accessing sprint otherwise it can happen that for example:
your stamina is 0.15 which is greater than 0 so you allow the player to sprint BUT this part:

if isSprinting and stamina > 0 and Humanoid.MoveDirection.Magnitude > 0 then
        Humanoid:SetAttribute("Stamina", stamina - (staminaDrain * dt))

may be deducting 0.47 since drain is higher than regenerating
so in this case you end up negative which should explain the negative number
so a simple check (if you still hold down shift) should do the trick

#

so maybe check that:

UIS.InputBegan:Connect(function(input)
    if input.KeyCode ~= Enum.KeyCode.LeftShift then return end
    if (stamina - (staminaDrain * dt)) >= Humanoid:GetAttribute("Stamina") then return end
    isSprinting = true
    sprint(isSprinting)
end)

something like this should do the trick @whole herald

whole herald
#

anyway for me to get dt into the UIS function? it now just tells me dt is not a global