Bar Size Speeding up faster and faster once it reaches a certain point after the click

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)

Need help.

You never disconnect the RenderStepped, causing it to stack. You should declare it as a variable, and when it no longer has use, disconnect it.

1 Like

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.

1 Like

Thanks to both of you. Ill disconnect it forgot it needed one

No problem! If it doesn’t work then come back and Ill try help if I can

Im having small brain moment on where im suppose to disconnect it

Something like this should work

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

2 Likes

I figured this out already but thanks for helping.

Oh no problem! Have a good day!