Hey, I just finished fixing my stamina system and I found a bug that if you press Jump (takes 10 stamina away) and Q (Takes 20 Stamina Away) at the same time it does this bug that makes them both fill the stamina bar too quickly. I want it to only fill 0.25 even when you press q and jump and the same time or shift and q and shift and jump
Here is how it should be:
22:30:53.859 SlideUsed Stamina Being Filled (x77) - Client - Keybind:108
22:31:05.066 JumpUsed Stamina Being Filled (x80) - Client - Keybind:138
22:31:21.299 StaminaUsed Stamina Being Filled (x55) - Client - Keybind:77
Here is the code
local UIS = game:GetService("UserInputService")
local Player = game.Players.LocalPlayer
local Character = Player.Character
local Humanoid = Character:WaitForChild("Humanoid" ,5)
local StaminaUsed = script:WaitForChild("StaminaUsed" ,5)
local Keybind = "LeftShift"
local MaxStamina = 100
local NormalWalkspeed = 16
local SprintWalkspeed = 25
anim = Instance.new("Animation")
anim.AnimationId = "rbxassetid://8107329636"
animPlay = Humanoid:LoadAnimation(anim)
local StaminaCount = MaxStamina
local SlideUsed = script.Slided
local JumpUsed = script.Jumped
local breathing = script.Parent["Heavy Breathing ( Man )"]
UIS.InputBegan:Connect(function(key, processed)
if key.UserInputType == Enum.UserInputType.Keyboard then
if key.KeyCode == Enum.KeyCode[Keybind] and StaminaCount > 0 then
StaminaUsed.Value = true
elseif key.KeyCode == Enum.KeyCode.Q and StaminaCount > 0 then
SlideUsed.Value = true
elseif key.KeyCode == Enum.KeyCode.Space and StaminaCount > 0 then
JumpUsed.Value = true
end
end
end)
UIS.InputEnded:Connect(function(key, processed)
if key.UserInputType == Enum.UserInputType.Keyboard then
if key.KeyCode == Enum.KeyCode[Keybind] then
StaminaUsed.Value = false
elseif key.KeyCode == Enum.KeyCode.Q then
SlideUsed.Value = false
elseif key.KeyCode == Enum.KeyCode.Space then
JumpUsed.Value = false
end
end
end)
StaminaUsed.Changed:Connect(function()
if StaminaUsed.Value == true and Humanoid.MoveDirection.Magnitude > 0 then
Humanoid.WalkSpeed = SprintWalkspeed
animPlay:Play()
for i = 1,5 do
game.Workspace.CurrentCamera.FieldOfView = (70+(i*2))
wait()
end
repeat
wait(0.1)
if StaminaCount > 0 then
StaminaCount = StaminaCount - 1
script.Parent.Frame.Size = UDim2.new(StaminaCount / MaxStamina, 0, 1, 0)
script.Parent.Info.Text = StaminaCount.. "/" ..MaxStamina
end
until
StaminaCount <= 0 or StaminaUsed.Value == false
Humanoid.WalkSpeed = NormalWalkspeed
elseif StaminaUsed.Value == false then
Humanoid.WalkSpeed = NormalWalkspeed
animPlay:Stop()
breathing.Playing = false
for i = 1,5 do
game.Workspace.CurrentCamera.FieldOfView = (80-(i*2)) -- make FOV smaller
wait()
end
repeat
wait(0.1)
if StaminaCount < MaxStamina then
StaminaCount = StaminaCount + 1
script.Parent.Frame.Size = UDim2.new(StaminaCount / MaxStamina, 0, 1, 0)
script.Parent.Info.Text = StaminaCount.. "/" ..MaxStamina
print("StaminaUsed Stamina Being Filled")
end
until
StaminaCount == MaxStamina or StaminaUsed.Value == true and JumpUsed.Value == false and SlideUsed.Value == false
end
end)
SlideUsed.Changed:Connect(function()
if SlideUsed.Value == true then
local deb2 = true
if StaminaCount > 0 and deb2 == true then
deb2 = false
StaminaCount = StaminaCount - 10
script.Parent.Frame.Size = UDim2.new(StaminaCount / MaxStamina, 0, 1, 0)
script.Parent.Info.Text = StaminaCount.. "/" ..MaxStamina
wait(1.2)
deb2 = true
end
elseif SlideUsed.Value == false then
Humanoid.WalkSpeed = NormalWalkspeed
animPlay:Stop()
for i = 1,5 do
game.Workspace.CurrentCamera.FieldOfView = (80-(i*2)) -- make FOV smaller
wait()
end
repeat
wait(0.1)
if StaminaCount < MaxStamina then
StaminaCount = StaminaCount + 0.25
script.Parent.Frame.Size = UDim2.new(StaminaCount / MaxStamina, 0, 1, 0)
script.Parent.Info.Text = StaminaCount.. "/" ..MaxStamina
print("SlideUsed Stamina Being Filled")
end
until
StaminaCount == MaxStamina or SlideUsed.Value == true and JumpUsed.value == false and StaminaUsed.Value == false
end
end)
JumpUsed.Changed:Connect(function()
if JumpUsed.Value == true then
local deb3 = true
if StaminaCount > 0 and deb3 == true then
deb3 = false
StaminaCount = StaminaCount - 10
script.Parent.Frame.Size = UDim2.new(StaminaCount / MaxStamina, 0, 1, 0)
script.Parent.Info.Text = StaminaCount.. "/" ..MaxStamina
wait(1.2)
deb3 = true
end
elseif JumpUsed.Value == false then
Humanoid.WalkSpeed = NormalWalkspeed
animPlay:Stop()
for i = 1,5 do
game.Workspace.CurrentCamera.FieldOfView = (80-(i*2)) -- make FOV smaller
wait()
end
repeat
wait(0.1)
if StaminaCount < MaxStamina then
StaminaCount = StaminaCount + 0.25
script.Parent.Frame.Size = UDim2.new(StaminaCount / MaxStamina, 0, 1, 0)
script.Parent.Info.Text = StaminaCount.. "/" ..MaxStamina
print("JumpUsed Stamina Being Filled")
end
until
StaminaCount == MaxStamina or JumpUsed.Value == true and SlideUsed.Value == false and StaminaUsed.value == false
end
end)
You could make a debounce system, for example, you can jump every half a second. The best approach would be to check this debounce in the server to make it harder for exploiters to bypass this.
Here are some articles that could be handy:
Edit: For some reason the InputBegan event is fired more than once when you give any input, I’m not sure why but it happens
I added a debounce and tested the debounce and it still didn’t work
local UIS = game:GetService("UserInputService")
local Player = game.Players.LocalPlayer
local Character = Player.Character
local Humanoid = Character:WaitForChild("Humanoid" ,5)
local StaminaUsed = script:WaitForChild("StaminaUsed" ,5)
local Keybind = "LeftShift"
local MaxStamina = 100
local NormalWalkspeed = 16
local SprintWalkspeed = 25
anim = Instance.new("Animation")
anim.AnimationId = "rbxassetid://8107329636"
animPlay = Humanoid:LoadAnimation(anim)
local StaminaCount = MaxStamina
local SlideUsed = script.Slided
local JumpUsed = script.Jumped
local breathing = script.Parent["Heavy Breathing ( Man )"]
UIS.InputBegan:Connect(function(key, processed)
if key.UserInputType == Enum.UserInputType.Keyboard then
if key.KeyCode == Enum.KeyCode[Keybind] and StaminaCount > 0 then
StaminaUsed.Value = true
elseif key.KeyCode == Enum.KeyCode.Q and StaminaCount > 0 then
SlideUsed.Value = true
elseif key.KeyCode == Enum.KeyCode.Space and StaminaCount > 0 then
JumpUsed.Value = true
end
end
end)
UIS.InputEnded:Connect(function(key, processed)
if key.UserInputType == Enum.UserInputType.Keyboard then
if key.KeyCode == Enum.KeyCode[Keybind] then
StaminaUsed.Value = false
elseif key.KeyCode == Enum.KeyCode.Q then
SlideUsed.Value = false
elseif key.KeyCode == Enum.KeyCode.Space then
JumpUsed.Value = false
end
end
end)
StaminaUsed.Changed:Connect(function()
if StaminaUsed.Value == true and Humanoid.MoveDirection.Magnitude > 0 then
Humanoid.WalkSpeed = SprintWalkspeed
animPlay:Play()
for i = 1,5 do
game.Workspace.CurrentCamera.FieldOfView = (70+(i*2))
wait()
end
repeat
wait(0.1)
if StaminaCount > 0 then
StaminaCount = StaminaCount - 1
script.Parent.Frame.Size = UDim2.new(StaminaCount / MaxStamina, 0, 1, 0)
script.Parent.Info.Text = StaminaCount.. "/" ..MaxStamina
end
until
StaminaCount <= 0 or StaminaUsed.Value == false
Humanoid.WalkSpeed = NormalWalkspeed
elseif StaminaUsed.Value == false then
Humanoid.WalkSpeed = NormalWalkspeed
animPlay:Stop()
breathing.Playing = false
for i = 1,5 do
game.Workspace.CurrentCamera.FieldOfView = (80-(i*2)) -- make FOV smaller
wait()
end
repeat
wait(0.1)
if StaminaCount < MaxStamina then
StaminaCount = StaminaCount + 1
script.Parent.Frame.Size = UDim2.new(StaminaCount / MaxStamina, 0, 1, 0)
script.Parent.Info.Text = StaminaCount.. "/" ..MaxStamina
print("StaminaUsed Stamina Being Filled")
end
until
StaminaCount == MaxStamina or StaminaUsed.Value == true and JumpUsed.Value == false and SlideUsed.Value == false
end
end)
local deb2 = true
SlideUsed.Changed:Connect(function()
if SlideUsed.Value == true then
if StaminaCount > 0 and deb2 == true then
deb2 = false
StaminaCount = StaminaCount - 10
script.Parent.Frame.Size = UDim2.new(StaminaCount / MaxStamina, 0, 1, 0)
script.Parent.Info.Text = StaminaCount.. "/" ..MaxStamina
wait(1.2)
deb2 = true
end
elseif SlideUsed.Value == false then
Humanoid.WalkSpeed = NormalWalkspeed
animPlay:Stop()
for i = 1,5 do
game.Workspace.CurrentCamera.FieldOfView = (80-(i*2)) -- make FOV smaller
wait()
end
repeat
wait(0.1)
if StaminaCount < MaxStamina then
StaminaCount = StaminaCount + 0.25
script.Parent.Frame.Size = UDim2.new(StaminaCount / MaxStamina, 0, 1, 0)
script.Parent.Info.Text = StaminaCount.. "/" ..MaxStamina
print("SlideUsed Stamina Being Filled")
end
until
StaminaCount == MaxStamina or SlideUsed.Value == true and JumpUsed.value == false and StaminaUsed.Value == false
end
end)
local deb3 = true
JumpUsed.Changed:Connect(function()
if JumpUsed.Value == true then
if StaminaCount > 0 and deb3 == true then
deb3 = false
StaminaCount = StaminaCount - 10
script.Parent.Frame.Size = UDim2.new(StaminaCount / MaxStamina, 0, 1, 0)
script.Parent.Info.Text = StaminaCount.. "/" ..MaxStamina
wait(1.2)
deb3 = true
end
elseif JumpUsed.Value == false then
Humanoid.WalkSpeed = NormalWalkspeed
animPlay:Stop()
for i = 1,5 do
game.Workspace.CurrentCamera.FieldOfView = (80-(i*2)) -- make FOV smaller
wait()
end
repeat
wait(0.1)
if StaminaCount < MaxStamina then
StaminaCount = StaminaCount + 0.25
script.Parent.Frame.Size = UDim2.new(StaminaCount / MaxStamina, 0, 1, 0)
script.Parent.Info.Text = StaminaCount.. "/" ..MaxStamina
print("JumpUsed Stamina Being Filled")
end
until
StaminaCount == MaxStamina or JumpUsed.Value == true and SlideUsed.Value == false and StaminaUsed.value == false
end
end)
I’ve look that you add stamina gradually with a repeat and use wait to give a delay, do you know if the delay you’re giving of 0.1 seconds is enough? Can you also test if the wait is actually working; I’d also recommend changing the wait to task.wait is a new library Roblox created and it’s better, here a bit about it: task | Roblox Creator Documentation
I tested it by changing it to wait(1) and when I jumped it filled slowly and when I pressed q the same problem occurred
Updated Code
local UIS = game:GetService("UserInputService")
local Player = game.Players.LocalPlayer
local Character = Player.Character
local Humanoid = Character:WaitForChild("Humanoid" ,5)
local StaminaUsed = script:WaitForChild("StaminaUsed" ,5)
local Keybind = "LeftShift"
local MaxStamina = 100
local NormalWalkspeed = 16
local SprintWalkspeed = 25
anim = Instance.new("Animation")
anim.AnimationId = "rbxassetid://8107329636"
animPlay = Humanoid:LoadAnimation(anim)
local StaminaCount = MaxStamina
local SlideUsed = script.Slided
local JumpUsed = script.Jumped
local breathing = script.Parent["Heavy Breathing ( Man )"]
UIS.InputBegan:Connect(function(key, processed)
if key.UserInputType == Enum.UserInputType.Keyboard then
if key.KeyCode == Enum.KeyCode[Keybind] and StaminaCount > 0 then
StaminaUsed.Value = true
elseif key.KeyCode == Enum.KeyCode.Q and StaminaCount > 0 then
SlideUsed.Value = true
elseif key.KeyCode == Enum.KeyCode.Space and StaminaCount > 0 then
JumpUsed.Value = true
end
end
end)
UIS.InputEnded:Connect(function(key, processed)
if key.UserInputType == Enum.UserInputType.Keyboard then
if key.KeyCode == Enum.KeyCode[Keybind] then
StaminaUsed.Value = false
elseif key.KeyCode == Enum.KeyCode.Q then
SlideUsed.Value = false
elseif key.KeyCode == Enum.KeyCode.Space then
JumpUsed.Value = false
end
end
end)
StaminaUsed.Changed:Connect(function()
if StaminaUsed.Value == true and Humanoid.MoveDirection.Magnitude > 0 then
Humanoid.WalkSpeed = SprintWalkspeed
animPlay:Play()
for i = 1,5 do
game.Workspace.CurrentCamera.FieldOfView = (70+(i*2))
wait()
end
repeat
wait(0.1)
if StaminaCount > 0 then
StaminaCount = StaminaCount - 1
script.Parent.Frame.Size = UDim2.new(StaminaCount / MaxStamina, 0, 1, 0)
script.Parent.Info.Text = StaminaCount.. "/" ..MaxStamina
end
until
StaminaCount <= 0 or StaminaUsed.Value == false
Humanoid.WalkSpeed = NormalWalkspeed
elseif StaminaUsed.Value == false then
Humanoid.WalkSpeed = NormalWalkspeed
animPlay:Stop()
breathing.Playing = false
for i = 1,5 do
game.Workspace.CurrentCamera.FieldOfView = (80-(i*2)) -- make FOV smaller
wait()
end
repeat
task.wait(1)
if StaminaCount < MaxStamina then
StaminaCount = StaminaCount + 1
script.Parent.Frame.Size = UDim2.new(StaminaCount / MaxStamina, 0, 1, 0)
script.Parent.Info.Text = StaminaCount.. "/" ..MaxStamina
print("StaminaUsed Stamina Being Filled")
end
until
StaminaCount == MaxStamina or StaminaUsed.Value == true and JumpUsed.Value == false and SlideUsed.Value == false
end
end)
SlideUsed.Changed:Connect(function()
if SlideUsed.Value == true then
local deb2 = true
if StaminaCount > 0 and deb2 == true then
deb2 = false
StaminaCount = StaminaCount - 10
script.Parent.Frame.Size = UDim2.new(StaminaCount / MaxStamina, 0, 1, 0)
script.Parent.Info.Text = StaminaCount.. "/" ..MaxStamina
wait(1.2)
deb2 = true
end
elseif SlideUsed.Value == false then
Humanoid.WalkSpeed = NormalWalkspeed
animPlay:Stop()
for i = 1,5 do
game.Workspace.CurrentCamera.FieldOfView = (80-(i*2)) -- make FOV smaller
wait()
end
repeat
task.wait(1)
if StaminaCount < MaxStamina then
StaminaCount = StaminaCount + 0.25
script.Parent.Frame.Size = UDim2.new(StaminaCount / MaxStamina, 0, 1, 0)
script.Parent.Info.Text = StaminaCount.. "/" ..MaxStamina
print("SlideUsed Stamina Being Filled")
end
until
StaminaCount == MaxStamina or SlideUsed.Value == true and JumpUsed.value == false and StaminaUsed.Value == false
end
end)
JumpUsed.Changed:Connect(function()
if JumpUsed.Value == true then
local deb3 = true
if StaminaCount > 0 and deb3 == true then
deb3 = false
StaminaCount = StaminaCount - 10
script.Parent.Frame.Size = UDim2.new(StaminaCount / MaxStamina, 0, 1, 0)
script.Parent.Info.Text = StaminaCount.. "/" ..MaxStamina
wait(1.2)
deb3 = true
end
elseif JumpUsed.Value == false then
Humanoid.WalkSpeed = NormalWalkspeed
animPlay:Stop()
for i = 1,5 do
game.Workspace.CurrentCamera.FieldOfView = (80-(i*2)) -- make FOV smaller
wait()
end
repeat
task.wait(1)
if StaminaCount < MaxStamina then
StaminaCount = StaminaCount + 0.25
script.Parent.Frame.Size = UDim2.new(StaminaCount / MaxStamina, 0, 1, 0)
script.Parent.Info.Text = StaminaCount.. "/" ..MaxStamina
print("JumpUsed Stamina Being Filled")
end
until
StaminaCount == MaxStamina or JumpUsed.Value == true and SlideUsed.Value == false and StaminaUsed.value == false
end
end)
First, I’d recommend making a single function because these loops are almost the same, you could just add some parameters like delay, example:
function regenerateStamina(delayTime)
--This loop will stop if the MaxStamina was reached or the player performed any action that uses stamina
repeat
task.wait(1)
if StaminaCount < MaxStamina then
StaminaCount = StaminaCount + 0.25
script.Parent.Frame.Size = UDim2.new(StaminaCount / MaxStamina, 0, 1, 0)
script.Parent.Info.Text = StaminaCount.. "/" ..MaxStamina
print("Stamina Being Filled")
end
until StaminaCount == MaxStamina or JumpUsed.Value == true or SlideUsed.Value == true and StaminaUsed.Value == true
end
See if you change every loop to a call to this function, and if it still doesn’t work, then the problem isn’t in the loop itself
Note: I’m not sure if this could work too, but you could also wrap this function in its own thread:
this was what I was thinking of, but it might be the same as what I already did. I also think that you are on the right track but instead of calling the function in all of the inputs it should be only 1 input but im not sure how im going to do that
Updated Code
local UIS = game:GetService("UserInputService")
local Player = game.Players.LocalPlayer
local Character = Player.Character
local Humanoid = Character:WaitForChild("Humanoid" ,5)
local StaminaUsed = script:WaitForChild("StaminaUsed" ,5)
local Keybind = "LeftShift"
local MaxStamina = 100
local NormalWalkspeed = 16
local SprintWalkspeed = 25
anim = Instance.new("Animation")
anim.AnimationId = "rbxassetid://8107329636"
animPlay = Humanoid:LoadAnimation(anim)
local StaminaCount = MaxStamina
local SlideUsed = script.Slided
local JumpUsed = script.Jumped
local breathing = script.Parent["Heavy Breathing ( Man )"]
function regenerateStamina(delayTime,staminaType)
--This loop will stop if the MaxStamina was reached or the player performed any action that uses stamina
repeat
task.wait(delayTime)
if StaminaCount < MaxStamina then
StaminaCount = StaminaCount + 0.25
script.Parent.Frame.Size = UDim2.new(StaminaCount / MaxStamina, 0, 1, 0)
script.Parent.Info.Text = StaminaCount.. "/" ..MaxStamina
print(staminaType .. " Being Filled")
end
until StaminaCount == MaxStamina or JumpUsed.Value == true or SlideUsed.Value == true and StaminaUsed.Value == true
end
UIS.InputBegan:Connect(function(key, processed)
if key.UserInputType == Enum.UserInputType.Keyboard then
if key.KeyCode == Enum.KeyCode[Keybind] and StaminaCount > 0 then
StaminaUsed.Value = true
elseif key.KeyCode == Enum.KeyCode.Q and StaminaCount > 0 then
SlideUsed.Value = true
elseif key.KeyCode == Enum.KeyCode.Space and StaminaCount > 0 then
JumpUsed.Value = true
end
end
end)
UIS.InputEnded:Connect(function(key, processed)
if key.UserInputType == Enum.UserInputType.Keyboard then
if key.KeyCode == Enum.KeyCode[Keybind] then
StaminaUsed.Value = false
elseif key.KeyCode == Enum.KeyCode.Q then
SlideUsed.Value = false
elseif key.KeyCode == Enum.KeyCode.Space then
JumpUsed.Value = false
end
end
end)
StaminaUsed.Changed:Connect(function()
if StaminaUsed.Value == true and Humanoid.MoveDirection.Magnitude > 0 then
Humanoid.WalkSpeed = SprintWalkspeed
animPlay:Play()
for i = 1,5 do
game.Workspace.CurrentCamera.FieldOfView = (70+(i*2))
wait()
end
repeat
wait(0.1)
if StaminaCount > 0 then
StaminaCount = StaminaCount - 1
script.Parent.Frame.Size = UDim2.new(StaminaCount / MaxStamina, 0, 1, 0)
script.Parent.Info.Text = StaminaCount.. "/" ..MaxStamina
end
until
StaminaCount <= 0 or StaminaUsed.Value == false
Humanoid.WalkSpeed = NormalWalkspeed
elseif StaminaUsed.Value == false then
Humanoid.WalkSpeed = NormalWalkspeed
animPlay:Stop()
breathing.Playing = false
for i = 1,5 do
game.Workspace.CurrentCamera.FieldOfView = (80-(i*2)) -- make FOV smaller
wait()
end
regenerateStamina(0.25,"SprintStamina")
end
end)
SlideUsed.Changed:Connect(function()
if SlideUsed.Value == true then
local deb2 = true
if StaminaCount > 0 and deb2 == true then
deb2 = false
StaminaCount = StaminaCount - 10
script.Parent.Frame.Size = UDim2.new(StaminaCount / MaxStamina, 0, 1, 0)
script.Parent.Info.Text = StaminaCount.. "/" ..MaxStamina
wait(1.2)
deb2 = true
end
elseif SlideUsed.Value == false then
Humanoid.WalkSpeed = NormalWalkspeed
animPlay:Stop()
for i = 1,5 do
game.Workspace.CurrentCamera.FieldOfView = (80-(i*2)) -- make FOV smaller
wait()
end
regenerateStamina(0.25,"SlideStamina")
end
end)
JumpUsed.Changed:Connect(function()
if JumpUsed.Value == true then
local deb3 = true
if StaminaCount > 0 and deb3 == true then
deb3 = false
StaminaCount = StaminaCount - 10
script.Parent.Frame.Size = UDim2.new(StaminaCount / MaxStamina, 0, 1, 0)
script.Parent.Info.Text = StaminaCount.. "/" ..MaxStamina
wait(1.2)
deb3 = true
end
elseif JumpUsed.Value == false then
Humanoid.WalkSpeed = NormalWalkspeed
animPlay:Stop()
for i = 1,5 do
game.Workspace.CurrentCamera.FieldOfView = (80-(i*2)) -- make FOV smaller
wait()
end
regenerateStamina(0.25,"JumpStamina")
end
end)
Yes! That what I was thinking. It’s extremely simple:
local RunService = game:GetService("RunService")
function regenerateStamina(delayTime, staminaType)
local debounce = false
local usingAbility = function()
return JumpUsed.Value == true or SlideUsed.Value == true or StaminaUsed.Value == true
end
if StaminaCount < MaxStamina and not usingAbility() and not debounce then
debounce = true
StaminaCount = StaminaCount + 0.25
script.Parent.Frame.Size = UDim2.new(StaminaCount / MaxStamina, 0, 1, 0)
script.Parent.Info.Text = StaminaCount.. "/" ..MaxStamina
print(staminaType .. " Being Filled")
task.wait(delayTime)
debounce = false
end
end
RunService:BindToRenderStep("RegenerateStamina", 200, regenerateStamina)
function regenerateStamina(delayTime)
local debounce = false
local usingAbility = function()
return JumpUsed.Value == true or SlideUsed.Value == true or StaminaUsed.Value == true
end
if StaminaCount < MaxStamina and not usingAbility() and not debounce then
debounce = true
StaminaCount = StaminaCount + 0.25
script.Parent.Frame.Size = UDim2.new(StaminaCount / MaxStamina, 0, 1, 0)
script.Parent.Info.Text = StaminaCount.. "/" ..MaxStamina
print("Stamina Being Filled")
task.wait(delayTime)
debounce = false
end
end
RunService:BindToRenderStep("RegenerateStamina", 200, function()
regenerateStamina(1)
end)
Note: You’ve seen I removed the staminaType, well as this a general loop, I don’t think there’s a straightforward way to get that, and if you want different cooldowns for each type of ability, I’d say for doing it separated from this regeneration function
Sorry that was a mistake I did, you can’t create the delay variable inside the loop, otherwise it will always be false
local debounce = false
function regenerateStamina(delayTime)
local usingAbility = function()
return JumpUsed.Value == true or SlideUsed.Value == true or StaminaUsed.Value == true
end
if StaminaCount < MaxStamina and not usingAbility() and not debounce then
debounce = true
StaminaCount = StaminaCount + 0.25
script.Parent.Frame.Size = UDim2.new(StaminaCount / MaxStamina, 0, 1, 0)
script.Parent.Info.Text = StaminaCount.. "/" ..MaxStamina
print("Stamina Being Filled")
task.wait(delayTime)
debounce = false
end
end
RunService:BindToRenderStep("RegenerateStamina", 200, function()
regenerateStamina(1)
end)