In the Video the bar just keeps getting faster and faster but i want it to stay the same speed.
UIS.InputBegan:Connect(function(input, gameProcsessed)
local Cloned = Player:WaitForChild("PlayerGui"):FindFirstChild("BlockingStamina")
if on then
if gameProcsessed then return end
if equipped == false then return end
if Dashey then return end
if input.UserInputType == Enum.UserInputType.MouseButton2 then
blocking = true
BlockEvent:FireServer("One")
playanim:Play()
end
RunService.RenderStepped:Connect(function(deltaTime)
if blocking then
if not StaminaGone or (StaminaGone and currentstamina > 20) then
StaminaGone = false
currentstamina = math.clamp(currentstamina - 20 * deltaTime, 0, stamina)
if currentstamina == 0 then
blocking = false
playanim:Stop()
BlockEvent:FireServer("Two")
StaminaGone = true
end
else
BlockEvent:FireServer("Two")
playanim:Stop()
currentstamina = math.clamp(currentstamina + 10 * deltaTime, 0, stamina)
end
else
currentstamina = math.clamp(currentstamina + 10 * deltaTime, 0, stamina)
end
Cloned.Frame.BlockingStamina.Size = UDim2.new(currentstamina/stamina, 0, 1, 0)
end)
end
end)
UIS.InputEnded:Connect(function(input, IsTyping)
if IsTyping then return end
if not on then return end
if not equipped then return end
if input.UserInputType == Enum.UserInputType.MouseButton2 then
blocking = false
BlockEvent:FireServer("Two")
playanim:Stop()
end
end)
You’re never disconnecting the run service loop, this causes a stack that effectively gets faster, I suggest doing as dukzae said and declare it in a variable and then call :Disconnect() when needed.
UIS.InputBegan:Connect(function(input, gameProcsessed)
local Cloned = Player:WaitForChild("PlayerGui"):FindFirstChild("BlockingStamina")
if on then
if gameProcsessed then return end
if equipped == false then return end
if Dashey then return end
if input.UserInputType == Enum.UserInputType.MouseButton2 then
blocking = true
BlockEvent:FireServer("One")
playanim:Play()
end
local Connection -- Needs to be declared before
Connection = RunService.RenderStepped:Connect(function(deltaTime)
if blocking then
if not StaminaGone or (StaminaGone and currentstamina > 20) then
StaminaGone = false
currentstamina = math.clamp(currentstamina - 20 * deltaTime, 0, stamina)
if currentstamina == 0 then
blocking = false
playanim:Stop()
BlockEvent:FireServer("Two")
StaminaGone = true
Connection:Disconnect() -- I assume?
end
else
BlockEvent:FireServer("Two")
playanim:Stop()
currentstamina = math.clamp(currentstamina + 10 * deltaTime, 0, stamina)
end
else
currentstamina = math.clamp(currentstamina + 10 * deltaTime, 0, stamina)
end
Cloned.Frame.BlockingStamina.Size = UDim2.new(currentstamina/stamina, 0, 1, 0)
end)
end
end)
UIS.InputEnded:Connect(function(input, IsTyping)
if IsTyping then return end
if not on then return end
if not equipped then return end
if input.UserInputType == Enum.UserInputType.MouseButton2 then
blocking = false
BlockEvent:FireServer("Two")
playanim:Stop()
end
end)
if anything you’re better off just creating 2 separate functions to deal with blocking and attacking