Stamina Bar Not Decreasing when vaulting

The stamina bar doesn’t decrease when I try to vault.

local stamina = script.Parent.Settings.MaxStamina.Value
local vaulting = false
local Bar = script.Parent.Stamina.Bar
local vault = game.ReplicatedStorage.VAULTING

vault.OnServerEvent:Connect(function(plr,Proccesed)
	 vaulting = true
	if stamina > 0 and vaulting == true  then
		stamina = stamina - 100
		Bar.Size = UDim2.new(stamina/script.Parent.Settings.MaxStamina.Value ,0,1,0)

		wait()
	elseif stamina <= 0 then
			vaulting = false
			Bar.Size = UDim2.new(stamina/script.Parent.Settings.MaxStamina.Value ,0,0,0)
		end
	
end)
		


try this,

local stamina = script.Parent.Settings.MaxStamina
local vaulting = false
local Bar = script.Parent.Stamina.Bar
local vault = game.ReplicatedStorage.VAULTING

vault.OnServerEvent:Connect(function(plr,Proccesed)
	 vaulting = true
	if stamina.Value > 0 and vaulting == true  then
		stamina.Value -= 100
		Bar.Size = UDim2.new(stamina.Value/script.Parent.Settings.MaxStamina.Value ,0,1,0)

		wait()
	elseif stamina.Value <= 0 then
			vaulting = false
			Bar.Size = UDim2.new(stamina/script.Parent.Settings.MaxStamina.Value ,0,0,0)
		end
	
end)

wait I’ve just realized what you were trying to do, sorry (don’t use that code I sent)

Sorry if I didn’t explain well, but I want the Stamina Bar(bottom left) to decrease its value after I done the vaulting action:

local vault = game.ReplicatedStorage:WaitForChild("VAULTING")

vault.OnServerEvent:Connect(function(plr, Processed)
    local stamina = plr.Settings.MaxStamina.Value
    local vaulting = true
    local Bar = plr.Stamina.Bar
    
    if stamina > 0 and vaulting then
        local newStamina = stamina - 100 -- Decrease stamina by 100
        plr.Settings.MaxStamina.Value = newStamina -- Update the player's stamina
        
        -- Update the bar size based on the new stamina value
        Bar.Size = UDim2.new(newStamina / plr.Settings.MaxStamina.Value, 0, 1, 0)
        
        if newStamina <= 0 then
            vaulting = false
            Bar.Size = UDim2.new(0, 0, 0, 0) -- Reset the bar size if stamina is depleted
        end
    end
end)

Also:
Make so that plr.Settings.MaxStamina.Value correctly represents the player’s current stamina and not the maximum stamina capacity. If it’s meant to be the maximum capacity, you’ll need a separate attribute or variable to track the current stamina level you have