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

Any reason for stamina charge not working?

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?

2 comments

0

Mind if you can post the error & the error line?

0

there is no error .-.

1 answer

✓ Accepted answer

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)

1 comment

0

Thanks but it had the same effect as my script did. I added a debounce and it works. Thanks anyways.

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