Problem with a blocking script

My goal here is to make it so when the player presses F while stunned the script will yield, the problem here is that while I am stunned, I press F and release it a the player still blocks.

Here is the function:

local Block = {}
Block.StoredAnim = {}

function Block.Block(player,isBlocking)
	local character = player.Character
	local humanoid = character:FindFirstChild("Humanoid") :: Humanoid
	local HRP = character:FindFirstChild("HumanoidRootPart")
	local animator = humanoid.Animator :: Animator
	
	if CombatFunctions.CheckBlockState(character) then 
		while true do
			
			if not isBlocking then
				print("player is no longer trying to block")
				break
			end
			
			if not CombatFunctions.CheckBlockState(character) then
				print("player is now allowed to block")
				break
			end
			
			task.wait()
		end
		
		if not isBlocking then
			print("not blocking")
		end
		
		print(isBlocking)
	end
	
	if isBlocking then
		character:SetAttribute("Blocking",true)
		humanoid.WalkSpeed = 7
		humanoid.JumpHeight = 0
		
		Block.StoredAnim[character] = animator:LoadAnimation(BlockAnim)
		Block.StoredAnim[character]:Play()
	else
		character:SetAttribute("Blocking",false)
		humanoid.WalkSpeed = 20
		humanoid.JumpHeight = 7.2
		
		if Block.StoredAnim[character] then
			Block.StoredAnim[character]:Stop()
		end
		
	end
end

return Block

Its output:
image

Here is the checkBlockState function:

function CombatFunctions.CheckBlockState(character: Model)
	local attacking = character:GetAttribute("Attacking")
	local stunned = character:GetAttribute("Stunned")
	local ragdolled = character:GetAttribute("Ragdolled")
	local Dashing = character:GetAttribute("Dashing")

	if attacking or stunned or ragdolled or Dashing then return true else return false end
end

Here is the user input

--this is in the input began event dw
	if input.KeyCode == Enum.KeyCode.F then
		MainFunction:FireServer("Block",true)
	end
end)

UIS.InputEnded:Connect(function(input,GPE)
	if GPE then return end
	
	if input.KeyCode == Enum.KeyCode.F then
		MainFunction:FireServer("Block",false)
	end
end)

Here is what actually triggers the block function:

MainFunction.OnServerEvent:Connect(function(player,action,additional)
	local character = player.Character
	local humanoid = character:FindFirstChild("Humanoid") :: Humanoid
	local HRP = character:FindFirstChild("HumanoidRootPart")
	local animator = humanoid.Animator :: Animator
	
	if action == "LMB" then	
		AttackService.LMB(player,additional)
	end
	
	if action == "Block" then
		BlockService.Block(player,additional)
	end
end)

Thank you in advance for trying to help!