Instead of increasing the stamina by 10 every time, it increases by 10 the first time, then on the second it goes up by 30, then 70 and so on.
local Player = game.Players[script.Parent.Name] repeat wait() until Player and Player:WaitForChild("Stamina") ~= nil local MaxStamina = (100 + (1.5 * Player.Stats.Level.Value)) Player.Stamina.Changed:Connect(function() while Player.Stamina.Value < MaxStamina do wait(0.5) Player.Stamina.Value = Player.Stamina.Value + (10) if Player.Stamina.Value > MaxStamina then wait(0.05) Player.Stamina.Value = MaxStamina end end end)
any better way of writing this? Or any suggestions on the problem?
It is <= and >=, not < or >, second, you may use a while true do loop
wait() local Player = game.Players[script.Parent.Name] local MaxStamina = Player.Stats.Level.Value * 1.5 + 100 Player.Stamina.Changed:Connect(function() while true do MaxStamina = Player.Stats.Level.Value * 1.5 + 100 if Player.Stamina.Value >= MaxStamina then Player.Stamina.Value = MaxStamina wait() break end wait(0.5) Player.Stamina.Value = Player.Stamina.Value + 10 end end)