Progress bar problem

  1. What do you want to achieve?
    I want the bar to fill normally

  2. What is the issue? When you step back and press, at a moment when the action has not yet completely ended, then for some reason the action continues

  3. What solutions have you tried so far?
    I tried to change “return false” to “break” but even if everything works, it will not be so convenient

--initiate
if not func:Invoke(player, 5, part) then return end
--server script
local event = game:GetService("ReplicatedStorage").Remotes.ApplyingEvent
local func = game:GetService("ReplicatedStorage").Remotes.ApplyingFunc

local debounce = true

func.OnInvoke = function(player, waittime, part)
    if player:IsA("Model") and game:GetService("Players"):GetPlayerFromCharacter(player) then
        player = game:GetService("Players"):GetPlayerFromCharacter(player)
    end
    if player:IsA("Player") then
        event:FireClient(player, waittime, true)
        debounce = true
        delay(waittime, function()
            debounce = false
        end)
        if part then
            while debounce do
                if (player.Character.HumanoidRootPart.Position - part.Position).magnitude > 10 then
                    event:FireClient(player, waittime, false)
                    return false
                end
                wait()
            end
        end
        return true
    end
end
--local (the bar)
local player = game:GetService("Players").LocalPlayer
local gui = player.PlayerGui.MainGUI.CenterFrame.ApplyingFrame
local bar = gui.Frame.Bar
local event = game:GetService("ReplicatedStorage").Remotes.ApplyingEvent

event.OnClientEvent:Connect(function(waittime, bool)
    if bool then
        gui.Visible = true
        bar:TweenSize(UDim2.new(1,0,1,0), Enum.EasingDirection.InOut, Enum.EasingStyle.Linear, waittime)
        delay(waittime, function()
            bar.Size = UDim2.new(0,0,1,0)
            gui.Visible = false
        end)
    else
        bar.Size = UDim2.new(0,0,1,0)
        gui.Visible = false
    end
end)

If you add some print statements what do you see?

    if bool then
        print("Yes")
        gui.Visible = true
        bar:TweenSize(UDim2.new(1,0,1,0), Enum.EasingDirection.InOut, Enum.EasingStyle.Linear, waittime)
        delay(waittime, function()
            bar.Size = UDim2.new(0,0,1,0)
            gui.Visible = false
        end)
    else
        print("No")
        bar.Size = UDim2.new(0,0,1,0)
        gui.Visible = false
    end

Local script is working well, I need to fix server scripts issue

To continue making such a system (opening the vent) with a delay implemented on the server is problematic, and rather wrong and slow.

You can locally, via Proximity Prompt (use ProximityPromptService events for your own UI), wait for the bar to fill, and then simply send a request to the server to open this grid.