How to detect if a mouse button is being held for a certain amount of time?

I am currently trying to make a gun that requires to be “charged up” before firing.

The player would hold down right click until a bar reaches full, which would then allow them to fire. However, I am not sure how to accomplish this?

Here is what I currently have - any help would be greatly appreciated!

function Reset()
	
	if Player.PlayerGui:FindFirstChild("GunGUI") then
		 Player.PlayerGui:FindFirstChild("GunGUI"):Destroy()
	end
	
end

UIS.InputBegan:Connect(function(input, GPE)
	if (GPE) then
		return;
	end 

	broken = false
	
	local c = script.GunGUI:Clone()
	c.Parent = Player.PlayerGui
	
	for i= 1, Time do wait(0.5)

		if broken then
			return
			
		elseif c:FindFirstChild("Loading") then
			c.Loading.Size = UDim2.new(i/100,0,c.Loading.Size.Y.Scale,0)
		end
		
	end
	
	
	
	Reset()
	
	local MousePos = GetMousePos(Mouse.Hit)
	GunRemote:FireServer(MousePos)
	
	
end)

UIS.InputEnded:Connect(function(input, GPE)
	
	if (GPE) then
		return;
	end 
	
	broken = true
	Reset()

		
end)